#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
string n;
long long k, tot, ans, a[4], sum[N], mx[N];
void solve(long long cur, long long las);
void get_ans(long long cur);
signed main() {
  cin >> n >> k;
  tot = n.size();
  for (long long i = 0; i < tot; i++) {
    sum[i + 1] = sum[i];
    mx[i + 1] = n[i] - '0';
    if (n[i] - '0' == 0) {
      sum[i + 1]++;
    }
  }
  solve(1, 0);
  cout << ans << endl;
  return 0;
}
void solve(long long cur, long long las) {
  if (cur > k) {
    if (a[1] != 1) {
      ans += pow(9, k);
      return;
    }
    get_ans(1);
    return;
  }
  for (long long i = las + 1; i <= tot; i++) {
    a[cur] = i;
    solve(cur + 1, i);
  }
}
void get_ans(long long cur) {
  if (cur > k) {
    ans++;
    return;
  }
  if (mx[a[cur]] == 0) return;
  if (cur == 1) {
    ans += (mx[a[cur]] - 1) * pow(9, k - cur);
    get_ans(cur + 1);
  } else {
    if (sum[a[cur]] - sum[a[cur - 1]] == a[cur] - a[cur - 1] - 1) {
      ans += (mx[a[cur]] - 1) * pow(9, k - cur);
      get_ans(cur + 1);
    } else {
      ans += pow(9, k - cur + 1);
      return;
    }
  }
}
