#include <bits/stdc++.h>
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 8;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
using namespace std;
int t, n, m = 0, k = 0;
string s;
int ans = 0;
int C(int x, int y) {
  int cnt = 1;
  for (int i = 0; i < y; i++) cnt *= x--;
  for (int i = 2; i <= y; i++) cnt /= i;
  return cnt;
}
int p(int x) {
  int cnt = 1;
  while (x--) cnt *= 9;
  return cnt;
}
int main() {
  cin >> s;
  n = s.size() - 1;
  scanf("%d", &k);
  int i, j;
  for (i = k - 1, j = 0; i >= 0 && j <= n; i--, j++) {
    int cnt = s[j] - '0' - 1;
    if (cnt > 0) {
      ans += cnt * p(i) * C(n - j, i);
    }
    ans += p(i + 1) * C(n - j, i + 1);
  }
  if (ans == 0) ans = -1;
  printf("%d\n", ans + 1);
  return 0;
}
