#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

ll com(ll N, ll K) {
  ll ret=1;
  if(N>=K&&K!=0) {
    rep(i,K) ret*=(N-i);
    for(ll i=K;i>0;--i) ret/=i;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll k,ans=0;cin>>k;
  ll len=s.length(), head=s[0]-'0';
  if(k==1) ans=9*(len-1)+head;
  else if(k==2&&len>1) {
    ll a=0;
    for(ll i=2;i<len;++i) a+=9*9*(i-1);
    ll b=0,head1=s[1]-'0',len1=len-1;
    if(head1==0) 
    for(ll i=2;i<len;++i) {
      ll tmp=s[i]-'0';
      if(tmp!=0) {len1=len-i;head1=tmp;break;}
    } 
    if(head1!=0) {
      b+=(head-1)*9*(len-1);
      b+=9*(len1-1);
      b+=head1;
    }
    ans+=a+b;
  }
  else if(k==3&&len>2) {
    ll a=0;
    for(ll i=3;i<len;++i) a+=9*9*9*com(i-1,2);
    ll b=0,head1=s[1]-'0',len1=len-1;
    if(head1==0) 
    for(ll i=2;i<len;++i) {
      ll tmp=s[i]-'0';
      if(tmp!=0) {len1=len-i;head1=tmp;break;}
    }
    head2=s[len1+1]-'0',len2=len1-1;
    if(head2==0) 
    for(ll i=len-len1+1;i<len;++i) {
      ll tmp=s[i]-'0';
      if(tmp!=0) {len2=len-i;head2=tmp;break;}
    }
    if(head1*head2!=0) {
      b+=(head-1)*9*9*com(len-1,2);
      b+=head2*9*(len2-1);
      b+=head2*9*(len1-len2-1);
      b+=head1*9*(len2-1);
      b+=head1*9*(len1-len2-1);
      b+=9*9*com(len1-2,2);
      b+=head1*head2;
    }
    if(head1!=0&&head2==0&&len1>1) {
      b+=(head-1)*9*9*com(len-1,2);
      if(len1>2) b+=9*9*com(len1-1,2);
      b+=head1*9*(len1-1);
    }
    ans+=a+b;
  }
  print(ans);
  return 0;
}
