#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; }
long long triangle[105][105];
void go() {
  memset(triangle, 0, sizeof(triangle));
  triangle[0][0] = 1;
  for (long long i = 1; i < 105; i++) {
    triangle[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      triangle[i][j] = triangle[i - 1][j] + triangle[i - 1][j - 1];
    }
  }
  return;
}
void solve() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long f1 = (long long)s[0] - (long long)'0';
  long long l = s.length();
  long long ans = 0;
  if (k == 1) {
    ans = (9 * (l - 1)) + f1;
  }
  if (k == 2) {
    if (l >= 2) {
      long long f2 = (long long)s[1] - (long long)'0';
      ;
      ans = (triangle[l - 1][2] * 81) + ((f1 - 1) * (l - 1) * 9) + f2 +
            ((l - 2) * 9);
    }
  }
  if (k == 3) {
    if (l >= 3) {
      long long f2 = (long long)s[1] - (long long)'0';
      long long f3 = (long long)s[2] - (long long)'0';
      ans = (729 * triangle[l - 1][3]) + (81 * (f1 - 1) * triangle[l - 1][2]) +
            (81 * triangle[l - 2][2]) + (9 * (f2 - 1) * (l - 2)) +
            (9 * (l - 3)) + f3;
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  go();
  while (t--) {
    solve();
  };
  return 0;
}
