Go: ///
// File:  0546.go
// Author: ymiyamoto
//
// Created on Tue Mar  6 23:19:41 2018
//
package main

import (
	"fmt"
)

var n, k int

func perm(arr []int) [][]int {
	if len(arr) == 1 {
		return [][]int{arr}
	}

	p := perm(arr[1:])
	var ret [][]int
	for _, val := range p {
		for i := 0; i <= len(val); i++ {
			tmp := make([]int, len(val))
			copy(tmp, val)
			tmp = append(tmp, 0)
			copy(tmp[i+1:], tmp[i:])
			tmp[i] = arr[0]
			ret = append(ret, tmp)
		}
	}

	return ret
}

func permutation(n, k int) [][]int {
	ret := [][]int{}

	for i := 0; i < 1<<uint(n); i++ {
		var selects []int
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 == 1 {
				selects = append(selects, j)
			}
		}
		if len(selects) == k {
			ret = append(ret, perm(selects)...)
		}
	}

	return ret
}

func main() {
	for {
		fmt.Scan(&n, &k)
		if n == 0 && k == 0 {
			break
		}

		cards := make([]string, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&cards[i])
		}

		ret := permutation(len(cards), k)
		nums := map[string]bool{}
		for _, val := range ret {
			var num string
			for i := 0; i < len(val); i++ {
				num += cards[val[i]]
			}
			nums[num] = true
		}

		fmt.Println(len(nums))
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }


int main() {
	while (1) {
		int n, k;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		vector<string>s(n);
		set<string>se;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		sort(s.begin(), s.end());
		do {
			string builts;
			for (int i = 0; i < k; i++) {
				builts += s[i];
			}
			se.insert(builts);
		} while (next_permutation(s.begin(), s.end()));
		long long cnt = se.size();
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int n, k;
set<string> st;
void calc(int bit, vector<int> &v)
{
    vector<int> num;
    for(int i = 0; i < n; i++)
    {
        if(bit & (1<<i)) num.push_back(v[i]);
    }
    sort(num.begin(), num.end());
    do
    {
        string s = "";
        for(int i = 0; i < num.size(); i++) s += to_string(num[i]);
        st.insert(s);
    }
    while(next_permutation(num.begin(), num.end()));
}
void dfs(int bit, int pos, vector<int> &v)
{
    if(__builtin_popcount(bit) == k)
    {
        calc(bit, v);
        return;
    }
    if(pos >= n) return;
    dfs(bit, pos + 1, v);
    dfs(bit | (1<<pos), pos + 1, v);
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> k, n or k)
    {
        st.clear();
        vector<int> v(n);
        for(int i = 0; i < n; i++) cin >> v[i];
        dfs(0, 0, v);
        cout << st.size() << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int n, k;
set<string> st;
string a[10];
bool done[10];

void dfs(string s, int c) {
    if (c == k) {
        st.insert(s);
        return;
    }

    rep(i, n) {
        if (!done[i]) {
            done[i] = true;
            dfs(s + a[i], c + 1);
            done[i] = false;
        }
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while (cin >> n >> k, n) {
        rep(i, n) cin >> a[i];

        st.clear();
        fill(done, done + 10, false);
        dfs("", 0);
        cout << st.size() << endl;
    }

}

C++: #include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
using namespace std;
typedef long long ll;
const int INF=1000000;

int main(){
    int n, k, C[1000];
    while(1){
        cin >> n >> k;
        if(n==0 && k==0) break;
        for(int i=0; i<n; i++)
            cin >> C[i];
        sort(C, C+n);

        set<string> nums;
        do{
            string num="";
            for(int i=0; i<k; i++)
                num+=to_string(C[i]);
            nums.insert(num);
        }while(next_permutation(C, C+n));

        cout << nums.size() << endl;

        memset(C, 0, 1000*sizeof(int));
    }
    return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);


bool ans[100000011];
int a[11];
int n, k;

void calc(int i, int j, int qqq, int l) {
	int num = a[i];
	if (a[j] >= 10)num *= 100;
	else num *= 10;
	num += a[j];
	if (3 <= k) {
		if (a[qqq] >= 10)num *= 100;
		else num *= 10;
		num += a[qqq];
		if (4 <= k) {
			if (a[l] >= 10)num *= 100;
			else num *= 10;
			num += a[l];
		}
	}
	//cout << num << endl;
	//system("pause");
	ans[num] = true;
}

int main() {
	while (cin >> n >> k&&n&&k) {
		for (int i = 0; i < 100000011; i++)ans[i] = false;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int qqq = 0; qqq < n; qqq++) {
					for (int l = 0; l < n; l++) {
						if (i == j)continue;
						if (i == qqq)continue;
						if (i == l)continue;
						if (j == qqq)continue;
						if (j == l)continue;
						if (qqq == l)continue;
						calc(i, j, qqq, l);
					}
				}
			}
		}
		int s = 0;
		for (int i = 0; i < 100000000; i++) {
			if (ans[i])s++;
		}
		cout << s << endl;
	}
}

C++: #import<iostream>
#import<set>
#import<algorithm>
using namespace std;main(){int n,k,c[10],i,t;for(;cin>>n>>k,i=n;){for(;i--;)cin>>c[i];sort(c,c+n);set<int>s;do{for(i=t=0;i<k;++i)t=t*(c[i]>9?100:10)+c[i];s.insert(t);}while(next_permutation(c,c+n));cout<<s.size()<<endl;}}