import std.stdio, std.algorithm, std.conv,std.range,std.array,std.string;

bool nextPermutation(BidirectionalRange)
                    (ref BidirectionalRange range)
{
    if (range.empty) return false;

    auto i = retro(range);
    auto last = i.save;

    size_t n = 1;
    for (i.popFront(); !i.empty; i.popFront(), last.popFront(), n++)
    {
        if (i.front < last.front)
            break;
    }

    if (i.empty) {
        range.reverse();
        return false;
    }

    auto j = find!((a) => i.front < a)(
        takeExactly(retro(range), n));

    assert(!j.empty); // shouldn't happen since i.front < last.front
    swap(i.front, j.front);
    reverse(takeExactly(retro(range), n));

    return true;
}

void main()
{
    while(true)
    {
        //int n=readln.chomp.to!int;
        int n;
        string line=readln;
        try{n=line.chomp.to!int;}catch(Exception e){throw new Exception(line);}
        int k=readln.chomp.to!int;
        if(n==0&&k==0)break;

        int[int] count;
        string[] nums = n.iota.map!(a => readln.chomp).array;
        int[] index=n.iota.array;

        while(index.nextPermutation)
        {
            int concat=index[0..k].map!(i=>nums[i]).reduce!("a~b").to!int;
            count[concat]=0;
        }
        count.length.writeln;
    }
}