#include <bits/stdc++.h>
using namespace std;
long long COM(long long a, long long b) {
  long long x, y;
  x = 1;
  y = 1;
  long long cnt = b;
  if (b <= 0 || a < b) {
    return 0;
  } else {
    for (long long i = 1; i <= b; i++) {
      x *= (a - i + 1);
      y *= i;
    }
    return x / y;
  }
}
int main() {
  string N;
  long long ans = 0;
  int K;
  int len;
  cin >> N;
  cin >> K;
  len = N.size();
  if (K == 1) {
    ans = 9 * (len - 1);
    ans += (N[0] - '0');
    cout << ans << endl;
  } else if (K == 2) {
    if (len == 1) {
      cout << 0 << endl;
    } else {
      ans += COM(len - 1, 2) * 9 * 9;
      ans += 1 * (N[1] - '0') + 1 * COM(len - 2, 1) * 9;
      ans += ((N[0] - '0') - 1) * COM(len - 1, 1) * 9;
      cout << ans << endl;
    }
  } else {
    if (len == 1 || len == 2) {
      cout << 0 << endl;
    } else {
      ans += COM(len - 1, 3) * 9 * 9 * 9;
      ans += (N[2] - '0') + COM(len - 3, 1) * 9;
      ans += ((N[1] - '0') - 1) * COM(len - 2, 1) * 9 + COM(len - 2, 2) * 9 * 9;
      ans += ((N[0] - '0') - 1) * COM(len - 1, 2) * 9 * 9;
      cout << ans << endl;
    }
  }
}
