#include <bits/stdc++.h>
#include <sstream>
using namespace std;

int main() {
  string n;
  cin>>n;
  int k;
  cin>>k;
  int l=n.size();
  long long ans=0;
  if(k==1) {
    ans+=(l-1)*9;
    string a{n[0]};
    istringstream s=istringstream(a);
    int num;
    s>>num;
    ans+=num;
  }
  else if(k==2){
    ans+=(l-1)*(l-2)*81/2;
    string a{n[0]};
    string b{n[1]};
    istringstream s=istringstream(a);
    istringstream t=istringstream(b);
    int x,y;
    s>>x;
    t>>y;
    ans+=10*x+y-9;
    ans+=x*(l-2)*9;
  }
  else{
    ans+=729*(l-1)*(l-2)*(l-3)/6;
    string x{n[0]};
    string y{n[1]};
    string z{n[2]};
    istringstream s=istringstream(x);
    istringstream t=istringstream(y);
    istringstream u=istringstream(z);
    int a,b,c;
    s>>a;
    t>>b;
    u>>c;
    ans+=100*a+10*b+c-99;
    ans+=x*81*(l-2)*(l-3)/2
  }
  cout<<ans<<endl;
  
}