#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char s = getchar();
  for (; !isdigit(s); s = getchar())
    if (s == '-') f = -1;
  for (; isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
  x *= f;
}
}  // namespace
char s[201];
long long dp[202];
int k, n;
long long dfs(int pos, bool limit, int num, int pre) {
  if (pos == n + 1) return 0;
  int r = limit ? s[pos] - '0' : 9;
  long long ans = 0;
  if (num == k - 1) {
    ans = r + (n - pos) * 9;
    return ans;
  }
  for (int i = 0; i <= r; i++) {
    ans += dfs(pos + 1, limit && i == s[pos] - '0', i ? num + 1 : num, i);
  }
  if (!limit) dp[pos] = ans;
  return ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%s%d", s + 1, &k);
  n = strlen(s + 1);
  s[0] = '0';
  cout << dfs(1, true, 0, 0) << endl;
}
