#include <bits/stdc++.h>
using namespace std;
long long MM = 1000000000;
long long mod = MM + 7;
long long MMM = 9223372036854775807;
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long x, long long y) { return x / GCD(x, y) * y; }
long long fac(long long x) {
  if (x == 0) return 1;
  return x * fac(x - 1);
}
long long combination(long long n, long long r) {
  if (r * 2 > n) r = n - r;
  long long dividend = 1;
  long long divisor = 1;
  for (long long i = 1; i <= r; i++) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
int main() {
  string n;
  cin >> n;
  long long k;
  cin >> k;
  long long l = n.size();
  if (k == 1) {
    if (l == 1)
      cout << n[0] - '0' << endl;
    else
      cout << 9 * (l - 1) + (n[0] - '0') << endl;
    return 0;
  } else if (k == 2) {
    if (l == 1)
      cout << 0 << endl;
    else if (l == 2) {
      long long t = stoi(n);
    } else {
      cout << combination(l - 1, 2) * 81 + ((n[0] - '0') - 1) * 9 * (l - 1) +
                  9 * (l - 2) + (n[1] - '0')
           << endl;
    }
    return 0;
  } else {
    if (l == 1 || l == 2)
      cout << 0 << endl;
    else if (l == 3) {
      long long t = stoi(n);
      cout << ((n[0] - '0') - 1) * 81 + t % 100 - 10 - ((t % 100) / 10 - 1)
           << endl;
    } else {
      cout << combination(l - 1, 3) * 9 * 9 * 9 +
                  ((n[0] - '0') - 1) * 9 * 9 * combination(l - 1, 2) +
                  combination(l - 2, 2) * 81 +
                  ((n[1] - '0') - 1) * 9 * (l - 2) + 9 * (l - 3) + (n[2] - '0');
    }
    return 0;
  }
}
