#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
long long LBI(vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long UBI(vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
string n;
long long k, ans = 0, nonZero[2] = {}, cnt = 0;
int main() {
  cin >> n;
  cin >> k;
  for (int i = 0; i < (int(n.size())); ++i) {
    if (n[i] != '0' && cnt < 2 && i > 0) {
      nonZero[cnt] = i;
      cnt++;
    }
  }
  if (int(n.size()) < k) {
    cout << 0 << endl;
    return 0;
  }
  long long box = 1;
  for (int i = 0; i < (k); ++i) box *= int(n.size()) - 1 - i;
  for (int i = 0; i < (k); ++i) box /= i + 1;
  ans += pow(9, k) * box;
  switch (k) {
    case 1:
      ans += n[0] - '0';
      break;
    case 2:
      ans += (n[0] - '0' - 1) * 9 * (int(n.size()) - 1);
      if (int(n.size()) - nonZero[0] - 1 != 0) {
        ans += (n[nonZero[0]] - '0') * 9 * (int(n.size()) - nonZero[0] - 1) + 1;
      } else {
        ans += (n[nonZero[0]] - '0');
      }
      break;
    case 3:
      box = 1;
      for (int i = 0; i < (2); ++i) box *= int(n.size()) - 1 - i;
      for (int i = 0; i < (2); ++i) box /= i;
      ans += (n[0] - '0' - 1) * 81 * box;
      if (int(n.size()) - nonZero[0] - 1 != 0) {
        ans += (n[nonZero[0]] - '0' - 1) * 9 * (int(n.size()) - nonZero[0] - 1);
      } else {
        ans += (n[nonZero[0]] - '0' - 1);
      }
      if (cnt == 2) {
        ans += (n[nonZero[0]] - '0' - 1) * 9 * (int(n.size()) - nonZero[0] - 1);
        if (int(n.size()) - nonZero[1] - 1 == 0) {
          ans += (n[nonZero[1]] - '0') * 9 * (int(n.size()) - nonZero[1] - 1);
        } else {
          ans += (n[nonZero[1]] - '0') * 9;
        }
      } else {
        ans += (n[nonZero[0]] - '0' - 1) * 9 * (int(n.size()) - nonZero[0] - 1);
      }
  }
  cout << ans << endl;
  return 0;
}
