#include <bits/stdc++.h>
using namespace std;
long long choose(int l, int k) {
  if (k > l) {
    return 0;
  }
  if (k == 0) {
    return 1;
  } else if (k == 1) {
    return l;
  } else if (k == 2) {
    return (l * (l - 1)) / 2;
  } else {
    return (l * (l - 1) * (l - 2)) / 6;
  }
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int l = (int)n.size() - 1;
  long long ans1 = choose(l, k) * pow(9, k),
            ans2 = (n[0] - '0' - 1) * choose(l, k - 1) * pow(9, k - 1);
  k--;
  if (k == 0) {
    ans2++;
  } else if (k == 1) {
    int ind = -1;
    for (int i = 1; i < (int)n.size(); ++i) {
      if (n[i] != '0') {
        ind = i;
        break;
      }
    }
    if (ind != -1) {
      ans2 += (n[ind] - '0') + ((int)n.size() - 1 - ind) * 9;
    }
  } else {
    int ind = -1;
    for (int i = 1; i < (int)n.size(); ++i) {
      if (n[i] != '0') {
        ind = i;
        break;
      }
    }
    if (ind < (int)n.size() - 1) {
      ans2 += choose((int)n.size() - 1 - ind, 2) * 9 * 9;
      ans2 += (n[ind] - '0' - 1) * choose((int)n.size() - 1 - ind, 1) * 9;
      int kk = ind;
      for (int i = kk + 1; i < (int)n.size(); ++i) {
        if (n[i] != '0') {
          ind = i;
          break;
        }
      }
      if (ind != -1) {
        ans2 += (n[ind] - '0') + ((int)n.size() - 1 - ind) * 9;
      }
    }
  }
  cout << ans1 + ans2 << endl;
  return 0;
}
