#include <bits/stdc++.h>
using namespace std;
inline int comb(int n, int k) {
  if (k > n) return 0;
  if (k == 0) return 1;
  if (k == 1) return n;
  if (k == 2) return (n * (n - 1)) / 2;
  return (n * (n - 1) * (n - 2)) / 6;
}
inline int pot(int x, int k) {
  int result = 1;
  for (int i = int(0); i < int(k); i++) result *= x;
  return result;
}
void solve() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int size = s.size();
  long long ans = 0;
  for (int i = int(k); i < int(size); i++) {
    ans += 1LL * pot(9, k) * comb(i - 1, k - 1);
  }
  int rem_k = k;
  for (int i = 0; i < size && rem_k > 0; i++) {
    int d = s[i] - '0';
    int rem_size = size - i - 1;
    for (int j = int(1); j < int(d); j++) {
      ans += 1LL * pot(9, rem_k - 1) * comb(rem_size, rem_k - 1);
    }
    if (d > 0 && i > 0) {
      ans += 1LL * pot(9, rem_k) * comb(rem_size, rem_k);
    }
    if (d > 0) {
      rem_k--;
    }
  }
  ans++;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
