#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 1e4 + 7;
long long i, j, T, t, n, m, l, a, c, b, x, p, k, d, len;
int dp[106][5], f[1005][5];
string s;
int main() {
  ios::sync_with_stdio(false);
  memset(f, 0, sizeof(f));
  memset(dp, 0, sizeof(dp));
  cin >> s >> k;
  len = s.length();
  for (i = 1; i < 10; i++) f[i][1] = i;
  for (i = 10; i < 100; i++) {
    m = 0, f[i][1] = f[i - 1][1], f[i][2] = f[i - 1][2];
    a = i % 10, b = i / 10;
    if (a != 0) m++;
    if (b != 0) m++;
    f[i][m]++;
  }
  for (i = 100; i < 1000; i++) {
    m = 0, f[i][1] = f[i - 1][1], f[i][2] = f[i - 1][2], f[i][3] = f[i - 1][3];
    a = i % 10, b = i / 100, c = (i / 10) % 10;
    if (a != 0) m++;
    if (b != 0) m++;
    if (c != 0) m++;
    f[i][m]++;
  }
  for (i = 1; i < len; i++) {
    dp[i][1] = i * 9;
    dp[i][2] = i * (i - 1) * 81 / 2;
    dp[i][3] = i * (i - 1) * (i - 2) * 9 * 81 / 6;
  }
  if (len < 4) {
    m = 0;
    for (i = 0; i < len; i++) m = m * 10 + s[i] - 48;
    cout << f[m][k];
  } else {
    m = 0;
    for (i = 0; i < 3; i++) m = m * 10 + s[i] - 48;
    if (k == 1)
      cout << dp[len - 3][1] + f[m][1];
    else if (k == 2)
      cout << dp[len - 3][2] + f[m][1] * dp[len - 3][1] + f[m][2];
    else
      cout << dp[len - 3][3] + f[m][2] * dp[len - 3][1] +
                  f[m][1] * dp[len - 3][2] + f[m][3];
  }
  return 0;
}
