#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll C(ll n, ll k) {
  if (k == 0) {
    return 1;
  }
  if (k == 1) {
    return n;
  }
  if (k == 2) {
    return n * (n - 1) / 2;
  }
  if (k == 3) {
    return n * (n - 1) * (n - 2) / 6;
  }
}
ll power(ll x, ll t) {
  ll ret = 1;
  while (t--) {
    ret *= x;
  }
  return ret;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  if (n < k) {
    cout << 0 << '\n';
    return 0;
  }
  ll ans = 0;
  int b = s[0] - '0';
  if (k == 1) {
    ans += b;
    for (int i = 1; i < n; ++i) {
      ans += 9;
    }
    cout << ans << '\n';
    return 0;
  }
  if (k == 2) {
    ans += C(n - 1, 2) * power(9, 2);
    ans += (b - 1) * (n - 1) * 9;
    for (int i = 1; i < n; ++i) {
      if (i == 1) {
        ans += s[i] - '0';
      } else {
        ans += 9;
      }
    }
    cout << ans << '\n';
    return 0;
  }
  ans += C(n - 1, 3) * 9 * 9 * 9;
  ans += 1LL * (b - 1) * C(n - 1, k - 1) * power(9, k - 1);
  cout << ans << '\n';
  if (n > 1) {
    int c = s[1] - '0';
    ans += 1LL * (c - 1) * (n - 2) * 9;
    ans += 1LL * C(n - 2, 2) * 9 * 9;
  }
  if (n > 2) {
    for (int i = 2; i < n; ++i) {
      if (i == 2) {
        ans += s[i] - '0';
      } else {
        ans += 9;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
