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))
	}
}

Python: import itertools
while True:
    n = int(input())
    k = int(input())
    if n == 0 and k == 0:
        break
    li = [int(input()) for i in range(n)]
    p = list(itertools.permutations(li,k))
    s = set()
    for i in p:
        c  = ""
        for j in range(len(i)):
            c += str(i[j])
        if c in s:
            continue
        else:
            s.add(int(c))
    print(len(s))

Python: while True:
  n = int(input())
  k = int(input())
  if not n:
    break
  lst = [input() for i in range(n)]
  dic = dict()
  def func(num,selected):
    if num == 0:
      dic["".join([lst[i] for i in selected])] = 1
      return
    for i in range(n):
      if not i in selected:
        selected.append(i)
        func(num - 1, selected)
        selected.pop()
  func(k,[])

  print(len(dic))

Python: def s():
 from itertools import permutations as P
 for e in iter(input,'0'):
  n,k=int(e),int(input())
  C=[input()for _ in[0]*n]
  print(len(set(''.join(s)for s in P(C,k))))
if'__main__'==__name__:s()

Python: import sys
import itertools
if sys.platform =='win32':
	sys.stdin=open('input.txt')

def MAP(): return [int(x) for x in input().split()]

while True:
	N = int(input())
	K = int(input())

	if N==0 and K==0: break

	a = [int(input()) for _ in range(N)]

	perm = itertools.permutations(a, K)
	nums = []
	for p in perm:
		num = ''
		for s in p:
			num += str(s)
		nums.append(int(num))
	
	print(len(set(nums)))

Python: import itertools

while True:
    n = int(input())
    k = int(input())
    if n==0: break
    deck = []
    for _ in range(n):
        deck.append(input())
    ans = set()
    for it in itertools.permutations(deck,k):
        ans.add("".join(it))
    print(len(ans))

Python: import sys
from itertools import permutations

def main():
	while True:
		n = input()
		k = input()
		if n == k == 0:
			sys.exit(0)
		for i in xrange(n):
			input()
#		nums = [raw_input().strip() for i in xrange(n)]
#		result = set(["".join(p) for p in permutations(nums, k)])
#		print (len(result))

if __name__ == '__main__':
	sys.exit(main())

Python: import itertools

ans = []

while True:
	n = int(input())
	k = int(input())
	if n == 0 and k == 0:
		break

	cards = []
	ans_set = []

	for i in range(n):
		cards.append(input())

	for i in itertools.permutations(cards, k):
		ans_set.append(int("".join(i)))
	
	ans.append(len(set(ans_set)))

for i in ans:
	print(i)

Python: from itertools import permutations as P

while True:
    n, k = int(input()), int(input())
    if k == 0:
        break
    card = [int(input()) for _ in range(n)]
    print(len(set([''.join(map(str, s)) for s in set(P(card, k))])))

Python: from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0\n'):
 n,k=int(e),int(r())
 C=[r()[:-1]for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: # AOJ 0546: Lining up the cards
# Python3 2018.7.1 bal4u

import sys
from sys import stdin
input = stdin.readline

def rec(i, m):
	global n, k, ans
	if i >= k:
		if m not in dic:
			ans += 1
			dic[m] = 1
		return
	for j in range(n):
		if f[j]: continue
		f[j] = 1
		if c[j] < 10: rec(i+1, m*10 + c[j])
		else:         rec(i+1, m*100+ c[j])
		f[j] = 0

while True:
	n, k = int(input()), int(input())
	if n == 0: break
	dic = {}
	f = [0]*12
	c = [int(input()) for i in range(n)]
	ans = 0
	rec(0, 0)
	print(ans)

Python: from itertools import permutations

while True:
	n = input()
	k = input()
	if n == k == 0:
		break
	nums = [raw_input().strip() for i in xrange(n)]
	result = set(["".join(p) for p in permutations(nums, k)])
	print(len(result))

Python: from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0'):
 n,k=int(e),int(r())
 C=[r()for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: import itertools
while True:
    n,k=map(int,[input()]+[input()])
    if not n|k:
        break
    a=list()
    b=set()
    for i in range(n):
        a.append(int(input()))
    c=list(itertools.permutations(a,k))
    for i in c:
        s=str()
        for j in i:
            s+=str(j)
        b.add(s)
    print(len(b))

Python: while 1:
    n=int(input())
    k=int(input())
    if n==k==0:break
    card=[]
    ans=[]
    for i in range(n):
        card.append(str(input()))
    if k==2:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                ans.append(card[i]+card[j])
    elif k==3:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                for k in range(n):
                    if i==k or j==k:continue
                    ans.append(card[i]+card[j]+card[k])
    elif k==4:
        for i in range(n):
            for j in range(n):
                if i==j:continue
                for k in range(n):
                    if i==k or j==k:continue
                    for l in range(n):
                        if i==l or j==l or k==l:continue
                        ans.append(card[i]+card[j]+card[k]+card[l])    
    ans=list(set(ans))
    print(len(ans))

Python: from itertools import permutations as P
import sys
r=sys.stdin.readline
for e in iter(r,'0\n'):
 n,k=int(e),int(r())
 C=[r()[:-1]for _ in[0]*n]
 print(len(set(''.join(s)for s in P(C,k))))

Python: import sys
from itertools import permutations

while True:
	n = input()
	k = input()
	if n == k == 0:
		sys.exit(0)
	nums = [raw_input().strip() for i in xrange(n)]
	result = set(["".join(p) for p in permutations(nums, k)])
	print(len(result))

Python: from itertools import permutations as P

while True:
    n, k = int(input()), int(input())
    if k == 0:
        break
    card = [input() for _ in range(n)]
    print(len(set([''.join(s) for s in P(card, k)])))

C++: #include<bits/stdc++.h>
#define LL long long
static const LL INF = 1<<50;

using namespace std;

int n,k,ans;
LL s[10001];
string num[11];
int t=0;
void cal(string sum,int depth,int bit){
    if(depth==k){
        int num;
        num=atoi(sum.data());
        s[t]=num;
        t++;
        return;
    }
    for(int i=1;i<=n;++i){
        int b=1<<i;
        if(bit&b){
            int k=bit-b;
            cal(sum+num[i],depth+1,k);
        }
    }
}

int main(){
    while(1){
        memset(s,0,sizeof(s));
        int p=1;
        t=0;
        cin>>n>>k;
        if(n==0&&k==0)break;
        for(int i=1;i<=n;++i){
            p+=pow(2,i);
            cin>>num[i];
        }
        cal("",0,p);
        sort(s,s+t);
        for(int i=0;i<t;++i){
            if(s[i]&&s[i]!=s[i+1]){
                ans++;
            }
        }
        cout<<ans<<endl;
        ans=0;
    }
}