#include <bits/stdc++.h>
using namespace std;
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline long long mnz(long long& a, long long b) { return a = (a > b ? b : a); }
inline long long mxz(long long& a, long long b) { return a = (a < b ? b : a); }
inline string toString(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
double const eps = 1e-6;
long long const Base = 1e9 + 7, oo = 1e17, MAXN = 1e6;
long long A[MAXN + 5];
long long Solves() {
  long long n, m, k, cnt = 0, ans = 0, x, y, q, c, sum = 0, v, t;
  string s;
  cin >> s >> k;
  n = (long long)s.length() - 1;
  if (k == 1) {
    for (long long i = 1; i <= n; i++) ans += 9;
    for (long long i = '1'; i <= s[0]; i++) ans++;
  } else if (k == 2) {
    for (long long i = 1; i <= n; i++) ans += 9 * 9 * (i - 1);
    if (n >= 1) {
      for (long long i = '1'; i <= s[0]; i++) {
        if (i < s[0]) {
          ans += 9 * (n);
        } else {
          v = 0;
          for (long long j = 1; j <= (long long)s.length() - 1; j++) {
            if (v)
              ans += 9;
            else
              ans += s[j] - '0';
            if (s[j] != '0') v = 1;
          }
        }
      }
    }
  } else if (k == 3) {
    for (long long i = 1; i <= n; i++)
      ans += 9LL * 9LL * 9LL * (i - 1) * (i - 2) / 2;
    if (n >= 2) {
      for (long long i = '1'; i <= s[0]; i++) {
        if (i < s[0]) {
          ans += 9LL * 9LL * (n - 1) * (n) / 2;
        } else {
          v = 0;
          for (long long j = 1; j <= (long long)s.length() - 1; j++) {
            if (v)
              c = 9;
            else
              c = s[j] - '0';
            long long vv = 0;
            for (long long h = j + 1; h <= (long long)s.length() - 1; h++) {
              if (v) {
                ans += c * 9;
              } else {
                if (vv)
                  ans += c * 9;
                else
                  ans += c * (s[h] - '0');
              }
              if (s[h] != '0') vv = 1;
            }
            if (s[j] != '0') v = 1;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  if (fopen("locin.txt", "r")) freopen("locin.txt", "r", stdin);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  for (long long T = 1; T <= test; T++) {
    Solves();
  }
}
