#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 1000010
#define db double
int main(){
   string s;
   cin>>s;
   int len=s.length();
   int k;
   cin>>k;
   ll ans=0;
   int a[len+5]={0};
    for (int m = 0; m <len ; ++m) {
        a[m+1]=a[m];
        if(a[m]!='0')a[m+1]++;
    }
   if(k==1){
       ans+=s[0]-'0';
       for (int i = 1; i <len ; ++i) {
           if(s[i]=='0')ans+=9;
           else ans+=s[i]-'0';
       }
       cout<<ans;
       return 0;
   }
   if(k==2){
       for (int i = 0; i <len ; ++i) {
           for (int j = i+1; j <len ; ++j) {
              if(i==0){
                if(a[j]==1) ans+=s[j]-'0'+(s[i]-'0'-1)*9;
                else ans+=(s[i]-'0')*9;
              }
              else ans+=81;
           }
       }
   }
   if(k==3){
       for (int i = 0; i <len ; ++i) {
           for (int j = i+1; j <len ; ++j) {
               for (int l = j+1; l <len ; ++l) {
                   ll tmp;
                   if(i==0){
                       if(a[j]==1)tmp=s[j]-'0'+(s[i]-'0'-1)*9;
                       else tmp=(s[i]-'0')*9;
                       if(a[l]==2)tmp=s[l]-'0'+(tmp-1)*9;
                       else if(a[l]>2)tmp*=9;
                   }
                   else tmp=9*9*9;
                   ans+=tmp;
               }
           }
       }
   }
   cout<<ans;
   return 0;

}