#include<bits/stdc++.h>
int chin(char a) {
  int ic[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  for (int i = 0; i < 10; i ++) {
    if (ic[i] == a) return i;
  }
  return 10;
}
using namespace std;
int main () {
  long long key[4][103];
  key[1][0] = key[2][0] = key[3][0] = 0;
  key[1][1] = 9LL;
  key[2][1] = key[3][1] = 0LL;
  for (int i = 1; i < 100; i ++) {
    key[1][i + 1] = key[1][i] + 9;
    key[2][i + 1] = key[2][i] + key[1][i] * 9;
    key[3][i + 1] = key[3][i] + key[2][i] * 9;
  }
  string N;
  cin >> N;
  int k;
  cin >> k;
  long long ans = key[k][N.size() - 1];
  if (N.size < k) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    ans += (long long)ic[N[0]];
    cout << ans << endl;
  }
  if (k == 2) {
    ans += (long long) (ic[N[0]] - 1) * (N.size() - 1) * 9;
    int k = 1;
    while(N[k] == '0' && k < N.size()) k ++;
    if (N.size() < k) cout << ans << endl;
    else {
      ans += (long long)ic(N[k]);
      ans += (long long) 9 * (N.size() - k - 1);
      cout << ans << endl;
    }
  }
  if (k == 3) {
    long long ol = (long long) (ic[N[0]] - 1) * (N.size() - 1) * 
      (N.size() - 2) * 81;
    ol /= 2;
    ans += ol;
    
  