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++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑

int digits(int n) {
	int ans = 0;
	while (n) {
		++ans;
		n /= 10;
	}
	return ans;
}


int main() {
	int a, b, k[15];
	while (cin >> a && a > 0) {
		cin >> b;
		set<ll>s;
		for (int i = 0; i < a; ++i) { cin >> k[i]; }
		if (b == 2) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					if (i == j) { continue; }
					s.insert(k[i] + k[j] * pow(10, digits(k[i])));
				}
			}
		}

		if (b == 3) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					for (int kk = 0; kk < a; ++kk) {
						if (i == j || j == kk || i == kk) { continue; }
						s.insert(k[i] + k[j] * pow(10, digits(k[i])) + k[kk] * pow(10, digits(k[i]) + digits(k[j])));
					}
				}
			}
		}

		if (b == 4) {
			for (int i = 0; i < a; ++i) {
				for (int j = 0; j < a; ++j) {
					for (int kk = 0; kk < a; ++kk) {
						for (int l = 0; l < a; ++l) {
							if (i == j || j == kk || i == kk || i == l || j == l || kk == l) { continue; }
							s.insert(k[i] + k[j] * pow(10, digits(k[i])) + k[kk] * pow(10, digits(k[i]) + digits(k[j])) + k[l] * pow(10, digits(k[i]) + digits(k[j]) + digits(k[kk])));
						}
					}
				}
			}
		}

		cout << s.size() << endl;
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int n, k, ans = 0, roop, num, save3, roop2, card[10], res, save2,save5[10];
bool save[10000000];
void solve(int a){
	roop--;
	for (int i = 0; i<n; i++){
		if(i==a) continue;
		if (save3 != i){
			if (roop == 0){
				save2 = res;
				if(card[i]/10>=1){
					res = res*100;
				}
				else{
					res = res*10;
				}
				res += card[i];
				if (save[res] == 0){
					ans++;
					save[res]=1;
				}
				res = save2;
			}
			else{
				if(card[i]/10>=1){
					res = res*100;
				}
				else{
					res = res*10;
				}
				res += card[i];
				solve(i);
				roop++;
				res -= card[i];
				if(res%100==0)
					res=res/100;
				if(res%10==0)
					res=res/10;
			}
		}
	}
}
int main() {
	while (true){
		cin >> n >> k;
		roop2 = 0;
		if (n == 0 && k == 0){
			return 0;
		}
		for (int i = 0; i < n; i++){
			cin >> card[i];
		}
		for (int i = 0; i < n; i++){
			roop = k - 1;
			res = card[i];
			save3 = i;
			solve(i);
		}
		cout << ans << endl;
		for (int i = 0; i < 10000000; i++){
			save[i] = 0;
		}
	}
}

C++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;

/* const */
const int INF = 999999999;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

static int n, k;
vector<string> card;
set<string> chie;

signed main()
{
  while (cin >> n >> k, n || k) {
    card = vector<string>(n);
    REP(i, n) cin >> card[i];
    sort(ALL(card));
    do {
      string s;
      REP(i, k) s += card[i];
      chie.insert(s);
    } while (next_permutation(ALL(card)));
    print(chie.size());
    //cout << chie.size() << endl;
    chie.clear();
  }
  
  return 0;
}

C++: 
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
 
int main(){
  int n,k;
  while(cin >> n >> k, n){
    vector<string> a(n);
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    sort(a.begin(), a.end());
 
    set<string> ans;
    for(int bit=1;bit<(1<<n);bit++){
      if(__builtin_popcount(bit) == k){
        vector<string> use;
        for(int i=0;i<n;i++){
          if( (bit>>i)&1 ) use.push_back(a[i]);
        }
        do{
          string con;
          for(int i=0;i<k;i++) con += use[i];
          ans.insert(con);
        }while( next_permutation(use.begin(), use.end()) );
      }
    }
    cout << ans.size() << endl;
  }
}