#include <bits/stdc++.h>
using namespace std;
const int SZ = 112345;
const int MOD = 1e9 + 7;
int n, k;
char s[SZ];
long long int ans = 0;
long long int get3() { return ((n - 1) * (n - 2) * (n - 3)) / 6; }
long long int get2(int x) { return ((x - 1) * (x - 2)) / 2; }
int main() {
  scanf("%s%d", s, &k);
  n = strlen(s);
  if (k == 1) {
    ans = 9 * (n - 1) + (s[0] - '0');
  } else if (k == 2) {
    ans = 81ll * get2(n) + (s[0] - '0' - 1) * 9ll * (n - 1);
    for (int i = 1; i < n; i++) {
      ans += s[i] - '0';
      if (s[i] != '0') {
        ans += 9 * (n - i - 1);
        break;
      }
    }
  } else {
    ans = 729ll * get3() + (s[0] - '0' - 1) * 81ll * get2(n);
    for (int i = 1; i + 1 < n; i++) {
      ans += (s[i] - '0' - 1) * 9ll * (n - i - 1);
      for (int j = i + 1; j < n; j++) {
        ans += s[j] - '0';
        if (s[j] != '0') {
          ans += 9 * (n - j - 1);
          break;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
