#include <bits/stdc++.h>
using namespace std;
const unsigned long long int mod = 1e9 + 7;
const long long int inf = (long long int)1e18 + 2;
const long long int N = (long long int)1e6 + 2;
void solve() {
  string str;
  cin >> str;
  long long int k, ans = 0;
  cin >> k;
  if (str.size() < k) {
    cout << 0 << '\n';
    return;
  }
  if (k == 1) {
    long long int zz = str.size();
    ans += (zz - 1) * 9;
    ans += str[0] - '0';
    cout << ans << '\n';
    return;
  } else if (k == 2) {
    long long int zz = str.size();
    for (long long int j = 1; j < zz; j++) {
      long long int temp = zz - j;
      if (temp > 0) ans += (temp - 1) * 9 * 9;
      long long int f1 = 0;
      for (long long int oi = j - 1; oi > 0; oi--) f1 += str[oi] - '0';
      if (f1)
        ans += (((str[0] - '0') - 1)) * 9 + 9;
      else
        ans += ((str[0] - '0') - 1) * 9 + (str[j] - '0');
    }
    cout << ans << '\n';
    return;
  } else {
    long long int zz = str.size(), ans = 0;
    for (long long int i = 1; i < zz - 1; i++) {
      for (long long int j = i + 1; j < zz; j++) {
        long long int temp = zz - j;
        if (temp > 0) ans += (temp - 1) * 9LL * 9LL * 9LL;
        long long int f1 = 0, f2 = 0;
        for (long long int oi = i - 1; oi > 0; oi--) f1 += (str[oi] - '0');
        for (long long int oi = j - 1; oi > i; oi--) f2 += (str[oi] - '0');
        if (f1 > 0)
          ans += ((str[0] - '0')) * 9 * 9;
        else if (f2 > 0) {
          ans += (((str[0] - '0') - 1)) * 9 * 9 + ((str[i] - '0')) * 9;
        } else
          ans += (((str[0] - '0') - 1)) * 9 * 9;
        if ((str[i] - '0') != 0) ans += (str[i] - '0' - 1) * 9 + (str[j] - '0');
      }
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
