#include <bits/stdc++.h>
using namespace std;
int p[200000];
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
int main() {
  string s;
  cin >> s;
  int k, j;
  cin >> k;
  long long int x;
  if (k > s.size()) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    cout << s[0] - '0' + 9 * (s.size() - 1) << endl;
    return 0;
  } else if (k == 2) {
    x = 9 * 9 * (long long int)(s.size() - 1) * (long long int)(s.size() - 2) /
        2;
    x = x + (long long int)(s[0] - '0' - 1) * 9 * (long long int)(s.size() - 1);
    x = x + (s[1] - '0' + 9 * (long long int)(s.size() - 2));
    cout << x << endl;
    return 0;
  } else {
    x = 9 * 9 * 9 * (long long int)(s.size() - 1) *
        (long long int)(s.size() - 2) * (long long int)(s.size() - 3) / 6;
    x = x + (s[0] - '0' - 1) * 9 * 9 * (long long int)(s.size() - 1) *
                (long long int)(s.size() - 2) / 2;
    if (s[1] != '0') {
      x = x + 9 * 9 * (long long int)(s.size() - 2) *
                  (long long int)(s.size() - 3) / 2;
      x = x +
          (long long int)(s[1] - '0' - 1) * 9 * (long long int)(s.size() - 2);
      x = x + (s[2] - '0' + 9 * (long long int)(s.size() - 3));
      cout << x << endl;
      return 0;
    } else {
      long long int j = 1;
      while (s[j] == '0') {
        j++;
        if (j == s.size()) {
          cout << x << endl;
          return 0;
        }
      }
      if (j == s.size() - 1) {
        cout << x << endl;
        return 0;
      } else {
        x = x + (long long int)((s[j] - '0' - 1) * 9 * (s.size() - 1 - j));
        j = j + 1;
        while (s[j] == '0') {
          j++;
          if (j == s.size()) {
            if (s[j] != '0') x = x + s[j] - '0';
            cout << x << endl;
            return 0;
          }
        }
        x = x + s[j] - '0' - 1 + 9 * (long long int)(s.size() - 1 - j);
        cout << x << endl;
        return 0;
      }
    }
  }
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
