    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    inline int read(){
        int ret=0,pos=1;char c=getchar();
        while(!isdigit(c) && c!='-' )c=getchar();
        if(c=='-')	pos=-1,c=getchar();
        while(isdigit(c))ret=(ret<<3)+(ret<<1)+c-48,c=getchar();
        return pos*ret;
    }
    string n;
    int k;
    /*int ans[150];
    void add(int x){
    	int i=0;a[0]+=x;
    	while(a[i]>=10){
    		a[i+1]+=a[i]/10;
    		a[i]%=10;
    		i++;
    	}
    	if(a[i]==0) tp=i-1;
    	else tp=i;
    }
    void mul(int x){
    	int i=0;
    	int tag=0;
    	while(a[i]>=10 || i<=tp){
    		a[i]*=x;
    		a[i]+=tag;
    		tag=a[i]/10;
    		a[i]%=10;
    		i++;
    	}
    	if(a[i]==0) tp=i-1;
    	else tp=i;
    }*/
    int ans;
    int cnt,l,r;
    signed main(){
    	cin>>n;
    	k=read();
    	int len=n.length();
    	if(k==1){
            ans+=9*(len-1);
            ans+=(n[0]-'0');
    	}
    	else if(k==2){
    		cnt=(len-1)*(len-2)/2*81;
    		ans+=cnt;
    		l=n[0]-'0',r=n[1]-'0';
    		ans+=(l-1)*(len-1)*9;
    		len--;
    		l=n[1]-'0';
    		cnt=(len-1)*9+r;
    		ans+=cnt;
    	}
    	else{
    		int cnt=(len-1)*(len-2)*(len-3)/6*729;
    		ans+=cnt;
    		l=n[0]-'0',r=n[1]-'0';
    		ans+=(l-1)*(len-1)*(len-2)/2*81;
    		len--;
    		cnt=max((len-1)*(len-2)/2*81,0);
    		ans+=cnt;
    		l=n[1]-'0',r=n[2]-'0';
    		ans+=(l-1)*(len-1)*9;
    		len--;
    		l=n[2]-'0';
    		cnt=(len-1)*9+r;
    		ans+=cnt;
    	}
    	cout<<ans;
    }