#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;

ll choose(ll l, ll r){
  if(l < r || r <= 0) return 0;
  ll ret = 1;
  for(ll i = l; i >= l - r + 1; i--){
    ret *= i;
  }
  for(ll i = r; i >= 1; i--){
    ret /= i;
  }
  return ret;
}

ll func1(string n){
  ll f = n[0] - '0', ans = 0;
  ans += f;
  ans += choose(n.size() - 1, 1) * pow(9, 1);
  return ans;
}

ll func2(string n){
  ll f = n[0] - '0', ans = 0, zn = 0;
  for(int i = 1; i < n.size(); i++){
    ll x = n[i] - '0';
    if(x != 0){
      ans += x;
      ans += choose(n.size() - i - 1, 1 - zn) * pow(9, 1 - zn);
      break;
    }
  }
  ans += (f - 1) * choose(n.size() - 1, 1) * pow(9, 1);
  ans += choose(n.size() - 1, 2) * pow(9, 2);
  return ans;
}

ll func3(string n){
  ll f = n[0] - '0', s, t, ans = 0, cnt = 0, si, zn = 0;
  for(int i = 1; i < n.size(); i++){
    ll x = n[i] - '0';
    if(x != 0){
      cnt++;
      if(cnt == 1){
        s = x;
        si = i;
        zns = zn;
      }
      if(cnt == 2){
        t = x;
        ans += t;
        ans += choose(n.size() - i - 1, 1 - zn) * pow(9, 1 - zn);
        break;
      }
    }
    else zn++;
  }
  ans += (s - 1) * choose(n.size() - si - 1, 1 - zns) * pow(9, 1 - zns);
  ans += choose(n.size() - si - 1, 2 - zns) * pow(9, 2 - zns);
  ans += (f - 1) * choose(n.size() - 1, 2) * pow(9, 2);
  ans += choose(n.size() - 1, 3) * pow(9, 3);
  return ans;
}

void solve(){
  string n; cin >> n;
  int k; cin >> k;
  ll ans;
  if(k == 3) ans = func3(n);
  else if(k == 2) ans = func2(n);
  else ans = func1(n);
  cout << ans << endl;


  return;
}

int main(){
  solve();
  return 0;
}
