#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  static char _c;
  static bool _f;
  x = 0;
  _f = 0;
  _c = getchar();
  while (_c < '0' || '9' < _c) {
    if (_c == '-') _f = true;
    _c = getchar();
  }
  while ('0' <= _c && _c <= '9') {
    x = (x << 1) + (x << 3) + (_c & 15);
    _c = getchar();
  }
  if (_f) x = -x;
}
template <typename T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
inline void Max(T &x, T y) {
  if (x < y) x = y;
}
const int INF = 0x3f3f3f3f;
const double pi = (double)acos(-1.0);
const double eps = (double)1e-8;
const int MOD = (int)998244353;
const int maxn = (int)3e5 + 20;
const int maxm = (int)1e6 + 20;
inline int sig(double x) { return x < -eps ? -1 : eps < x; }
long long fp(long long a, long long n, long long MOD) {
  if (n < 0) a = fp(a, MOD - 2, MOD), n = -n;
  long long res = 1;
  for (; n; n >>= 1, a = a * a % MOD)
    if (n & 1) res = res * a % MOD;
  return res;
}
int n, x;
char s[maxn];
int dp[maxn][10][4];
int DP(int x, int y, int z, int bound) {
  if (dp[x][y][z] != -1) return dp[x][y][z];
  if (z == -1) return 0;
  if (x == n - 1) {
    if (y != 0 && z == 1) return 1;
    if (y == 0 && z == 0) return 1;
    return 0;
  }
  int ed = bound == 1 ? s[x + 1] - '0' : 9;
  int cnt = 0;
  for (int i = 0; i <= ed; i++) {
    cnt += DP(x + 1, i, z - (y != 0), i == ed);
  }
  return dp[x][y][z] = cnt;
}
void work() {
  cin >> s;
  n = strlen(s);
  cin >> x;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k <= x; k++) dp[i][j][k] = -1;
  int ans = 0;
  for (int i = 1; i <= s[0] - '0'; i++) ans += DP(0, i, x, i == s[0] - '0');
  for (int i = 1; i < n; i++)
    for (int j = 1; j <= 9; j++) ans += DP(i, j, x, 0);
  cout << ans << endl;
}
int main(int argc, char **argv) {
  int tc = 1;
  for (int ca = 1; ca <= tc; ca++) {
    work();
  }
  return 0;
}
