#include <bits/stdc++.h>
using namespace std;
template <class T>
T powmod(T a, long long b, long long m) {
  T res = 1;
  while (b) {
    if (b % 2) {
      res *= a;
      res %= m;
    }
    a = (a * a) % m;
    b /= 2;
  }
  return res;
}
long long cnt[101];
long long C(long long n, long long r) {
  if (n < r) {
    return 0;
  }
  long long res = 1;
  long long v1 = n - r, v2 = r;
  if (v1 < v2) swap(v1, v2);
  for (long long i = v1 + 1; i <= n; i++) {
    res *= i;
  }
  for (long long i = 1; i <= v2; i++) {
    res /= i;
  }
  return res;
}
long long mod = 1e9 + 7;
int32_t main() {
  cnt[0] = 0;
  string s;
  cin >> s;
  long long n = s.size();
  long long k;
  cin >> k;
  long long ans = 0;
  if (k == 1) {
    ans = s[0] - '0';
    ans += 9 * (n - 1);
  } else if (k == 2) {
    ans += s[1] - '0';
    for (long long i = 2; i < n; i++) {
      ans += 9;
    }
    ans += C(n - 1, 2) * 9 * 9;
    ans += C(n - 1, 1) * (s[0] - 1 - '0') * 9;
  } else {
    for (long long i = 1; i < n; i++) {
      for (long long j = i + 1; j < n; j++) {
        if (s[i] != '0') ans += s[j] - '0' + (s[i] - '0' - 1) * 9;
      }
    }
    ans += C(n - 1, 3) * 9 * 9 * 9;
    ans += C(n - 1, 2) * (s[0] - 1 - '0') * 9 * 9;
  }
  cout << ans << endl;
}
