#include <bits/stdc++.h>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = int(1e9 + 7);
double ex[1010];
long long nck(long long a, long long b) {
  if (a < b) return 0;
  if (a == b) return 1;
  if (b <= 1) return a;
  return nck(a - 1, b - 1) + nck(a - 1, b);
}
long long dp[110][3][2];
string second;
long long first(long long dig, long long k, bool less) {
  if (dig == -1) return (k == 0);
  if (k == 0) return 1;
  long long &res = dp[dig][k][less];
  if (res != -1) return res;
  if (less == true)
    res = 9LL * first(dig - 1, k - 1, true) + first(dig - 1, k, true);
  else {
    res = (second[dig] - '0' - 1) * first(dig - 1, k - 1, true);
    res += first(dig - 1, k - 1, false) + first(dig - 1, k, false);
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, (-1), sizeof(dp));
  cin >> second;
  long long n = second.size();
  long long k;
  cin >> k;
  assert(second[0] != '0');
  long long res = 0;
  reverse((second).begin(), (second).end());
  res = first(n - 1, k, false);
  cout << res << '\n';
  return 0;
}
