#include <bits/stdc++.h>
using namespace std;
long long n;
string num;
long long k;
long long res = 0;
long long C[123][4];
long long dp[123][4];
long long dfs(long long pos, long long left) {
  if (left == 0) return 1;
  if (pos > n) return 0;
  long long ss = 0;
  for (long long i = 0; i < num[pos - 1] - '0'; i++) {
    if (i == 0)
      ss += dp[n - pos][left];
    else
      ss += dp[n - pos][left - 1];
  }
  if (num[pos - 1] > '0') return ss + dfs(pos + 1, left - 1);
}
signed main() {
  C[0][0] = 1;
  for (long long i = 1; i <= 122; i++) {
    C[i][0] = 1;
    C[i][1] = i;
  }
  for (long long i = 2; i <= 122; i++) {
    for (long long j = 2; j <= min(3ll, i); j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
  }
  ios::sync_with_stdio(false);
  cin >> num >> k;
  n = num.length();
  for (long long i = 1; i < n; i++) {
    if (i < k) continue;
    res += 9 * C[i - 1][k - 1];
  }
  for (long long i = 0; i <= 122; i++) {
    dp[i][0] = 1;
  }
  for (long long i = 1; i <= 122; i++) {
    dp[i][1] = 9ll * C[i][1];
    if (i >= 2) dp[i][2] = 9ll * 9ll * C[i][2];
    if (i >= 3) dp[i][3] = 9ll * 9ll * 9ll * C[i][3];
  }
  cout << dfs(1, k) << endl;
  return 0;
}
