#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int n;
int k;

vector<int> card;
set< string > cd;
set< vector<int> > ccd;

/*
string IteratorToString(vector<int>::iterator begin, vector<int>::iterator end){
	string str = "";
	char ch[256];
	for(;begin < end;begin++){
		sprintf(ch,"%d",*begin);
		str += ch;
	}
	return str;
}
*/
string VectorToString(const vector<int> &vec){
	string str = "";
	for(int i=0;i<vec.size();i++){
		char ch[256];
		sprintf(ch,"%d",vec[i]);
		str += ch;
	}
	return str;
}

string VectorToDebugText(const vector<int> &vec){
	string str = "";
	for(int i=0;i<vec.size();i++){
		char ch[256];
		sprintf(ch,"%d",vec[i]);
		str += ch;
		str += ":";
	}
	return str;
}

void solve(int a,vector<int> v){
	if(v.size() == k){
		sort(v.begin(),v.end());
		ccd.insert(v);
		return;
	}
	if(a == n){return;}
	solve(a + 1,v);
	v.push_back(card[a]);
	solve(a + 1,v);
}


int main(){
	while(1){
		int self;
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0){
			break;
		}
		card.clear();
		cd.clear();
		ccd.clear();
		for(int i=0;i<n;i++){
			scanf("%d",&self);
			card.push_back(self);
		}
		vector<int> cc(k);
	
		sort(card.begin(),card.end());
		/*
		while(next_permutation(card.begin(),card.end())){
			 cd.insert(VectorToString(card.begin(),card.begin()+k));
		}
		*/
		solve(0,vector<int>());
		for(set<vector<int> >::iterator it = ccd.begin();it != ccd.end();it++){
			vector<int> vec = *it;
			sort(vec.begin(),vec.end());
			cd.insert(VectorToString(vec));
			//printf("[%s]\n",VectorToDebugText(vec).c_str());
			while(next_permutation(vec.begin(),vec.end())){
				//printf("%s\n",VectorToDebugText(vec).c_str());
				//printf("%s\n",VectorToString(vec).c_str());
				cd.insert(VectorToString(vec));
			}
		}
		printf("%d\n",cd.size());
	}
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

const vector<ll> d2{0, 1, 0, 2, 0, 1};
const vector<ll> d3{0, 0, 1, 0, 0, 1};
const vector<ll> d5{0, 0, 0, 0, 1, 0};



int main() {
    string s1,s2;
    cin>>s1>>s2;

    ll N = s1.size();
    ll M = s2.size();
    vector<vector<ll>>dp(N+1,vector<ll> (M+1));
  
    rep(i,N){
        dp[i+1][0] = i+1;
    }

    rep(i,M){
        dp[0][i+1] = i+1;
    }

    rep(i,N){
        rep(j,M){
            if(s1[i] == s2[j]){
                dp[i+1][j+1] = min({dp[i][j],dp[i+1][j]+1,dp[i][j+1]+1});
            }else{
                dp[i+1][j+1] = min({dp[i][j]+1 ,dp[i+1][j]+1,dp[i][j+1]+1});
            }
        }
    }

    cout<<dp[N][M]<<endl;
    return 0;
    

}

