#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int comb(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  if (k == 2) return n * (n - 1) / 2;
  if (k == 3) return n * (n - 1) * (n - 2) / 6;
}
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int a = (int)n.size();
  int d0 = n[0] - '0';
  int d1 = n[1] - '0';
  int d2 = n[2] - '0';
  if (a < k) {
    cout << 0 << endl;
    return 0;
  }
  int res;
  if (k == 1) {
    res = comb(a - 1, 1) * 9;
    res += d0;
  }
  if (k == 2) {
    res = comb(a - 1, 2) * 81;
    res += comb(a - 1, 1) * 9 * (d0 - 1);
    if (d1 >= 0) {
      res += comb(a - 2, 1) * 9;
      res += d1;
    }
  }
  if (k == 3) {
    res = comb(a - 1, 3) * 729;
    res += comb(a - 1, 2) * 81 * (d0 - 1);
    if (d1 >= 0) {
      res += comb(a - 2, 2) * 81;
      res += comb(a - 2, 1) * 9 * (d1 - 1);
      if (d2 >= 0) {
        res += comb(a - 3, 1) * 9;
        res += d2;
      }
    }
  }
  cout << res << endl;
}
