#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 110;
int dp[maxn][4][2];
char N[maxn];
int k, len;
int dfs(int idx, int c0, int flag) {
  if (idx > len) return c0 == k;
  if (c0 > k) return 0;
  int& ans = dp[idx][c0][flag];
  if (ans != -1) return ans;
  ans = 0;
  int bound = (flag) ? N[idx] - '0' : 9;
  for (int i = 0; i <= bound; i++) {
    ans += dfs(idx + 1, c0 + (N[i] != '0'), (flag && (i == bound)));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(dp, 255, sizeof(dp));
  N[0] = '0';
  scanf("%s", N + 1);
  len = strlen(N + 1);
  cin >> k;
  cout << dfs(1, 0, 1) << endl;
  return 0;
}
