#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e16;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string n;
  long long k;
  cin >> n >> k;
  if (n.length() < k) {
    cout << 0 << endl;
    return 0;
  }
  long long m = long long(n[0] - '0');
  long long digit = n.length() - 1;
  if (k == 1) {
    cout << 9 * digit + m << endl;
    return 0;
  }
  long long nex = 0, index = 0;
  for (long long i = 1; i < n.length(); i++)
    if (n[i] != '0') {
      nex = long long(n[i] - '0'), index = i;
      break;
    }
  if (k == 2) {
    cout << nex + 9 * max((digit - index), 0ll) +
                max(digit, 0ll) * (9 * (m - 1) + (digit - 1) * 9 * 9 / 2)
         << endl;
    return 0;
  }
  long long next2 = 0, index2 = 0;
  for (long long i = index + 1; i < n.length(); i++)
    if (n[i] != '0') {
      next2 = long long(n[i] - '0'), index2 = i;
      break;
    }
  long long res = next2 + 9 * max(0ll, (digit - index2));
  res += max(0ll, (nex - 1)) * 9 * max(0ll, (digit - index));
  res += 9 * 9 * max(0ll, (digit - index)) * (digit - index - 1) / 2;
  cout << res + max(digit, 0ll) * (9 * 9 * (m - 1) * (digit - 1) / 2 +
                                   9 * 9 * 9 * (digit - 1) * (digit - 2) / 6)
       << endl;
}
