#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

struct Info{
	int number;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

//base??¨comp??????????????????????????¢??°
bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void func(int n,int k){

	Info info[5041];
	int index = 0,cards[10],tmp;

	for(int i = 0; i < n; i++)scanf("%d",&cards[i]);

	//k????????????????????¶?????°
	if(k == 2){

		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				if(i != k){
					//???????????°??????????????????
					if(cards[k] >= 10){
						tmp = 100*cards[i] + cards[k];
					}else{
						tmp = 10*cards[i] + cards[k];
					}

					if(index == 0){
						info[0].number = tmp;
						index++;
					}else{ //??¢??????????????????????????°??¨?????????????????????
						bool Found = false;
						for(int p = 0; p < index; p++){
							if(info[p].number == tmp){
								Found = true;
								break;
							}
						}
						if(!Found){ //?????¨???????????´???????????????
							info[index].number = tmp;
							index++;
						}
					}
				}
			}
		}

		printf("%d\n",index);
	}else if(k == 3){
		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				for(int a = 0; a < n; a++){
					if(i != k && i != a && k != a){
						//???????????°??????????????????
						if(cards[a] >= 10){
							tmp = 100*cards[k] + cards[a];
						}else{
							tmp = 10*cards[k] + cards[a];
						}

						if(tmp <= 99){ //2???
							tmp += 100*cards[i];
						}else if(tmp <= 999){ //3???
							tmp += 1000*cards[i];
						}else{ //4???
							tmp += 10000*cards[i];
						}

						if(index == 0){
							info[0].number = tmp;
							index++;
						}else{ //??¢??????????????????????????°??¨?????????????????????
							bool Found = false;
							for(int p = 0; p < index; p++){
								if(info[p].number == tmp){
									Found = true;
									break;
								}
							}
							if(!Found){ //?????¨???????????´???????????????
								info[index].number = tmp;
								index++;
							}
						}
					}
				}
			}
		}
		printf("%d\n",index);
	}else{ //k == 4
		for(int i = 0; i < n; i++){
			for(int k = 0; k < n; k++){
				for(int a = 0; a < n; a++){
					for(int b = 0; b < n; b++){
						if(i != k && i != a && i != b && k != a && k != b && a != b){
							//???????????°??????????????????
							if(cards[b] >= 10){
								tmp = 100*cards[a] + cards[b];
							}else{
								tmp = 10*cards[a] + cards[b];
							}

							if(tmp <= 99){ //2???
								tmp += 100*cards[k];
							}else if(tmp <= 999){ //3???
								tmp += 1000*cards[k];
							}else{ //4???
								tmp += 10000*cards[k];
							}

							if(tmp <= 999){ //3???
								tmp += 1000*cards[i];
							}else if(tmp <= 9999){ //4???
								tmp += 10000*cards[i];
							}else if(tmp <= 99999){ //5???
								tmp += 100000*cards[i];
							}else{ //6???
								tmp += 1000000*cards[i];
							}
							if(index == 0){
								info[0].number = tmp;
								index++;
							}else{ //??¢??????????????????????????°??¨?????????????????????
								bool Found = false;
								for(int p = 0; p < index; p++){
									if(info[p].number == tmp){
										Found = true;
										break;
									}
								}
								if(!Found){ //?????¨???????????´???????????????
									info[index].number = tmp;
									index++;
								}
							}
						}
					}
				}
			}
		}
		printf("%d\n",index);
	}
}


int main(){

	int n,k;

	while(true){
		scanf("%d %d",&n,&k);

		if(n == 0 && k == 0)break;

		func(n,k);
	}

    return 0;
}

Measured memory_bytes: 3208