#include <bits/stdc++.h>
using namespace std;
char a[105];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> a;
  cin >> n;
  int ws;
  long long ans = 0;
  ws = strlen(a);
  if (n == 1) {
    for (int i = 1; i < ws; i++) ans += 9;
    ans += a[0] - '0';
  } else if (n == 2) {
    for (int i = 2; i < ws; i++) ans += 81 * (i - 1);
    ans += ((a[0] - '0') * 10 + (a[1] - '0') - 9 -
            ((a[0] - '0') * 10 + (a[1] - '0')) / 10) +
           (a[0] - '0') * 9 * (ws - 2);
  } else if (n == 3) {
    for (int i = 3; i < ws; i++) ans += 729 * ((i - 1) * (i - 2) * 0.5);
    int hhh = (a[0] - '0') * 100 + (a[1] - '0') * 10 + (a[2] - '0');
    ans += (hhh - 99 - (hhh / 10)) +
           (a[0] - '0') * 81 * ((ws - 3) * (ws - 4) * 0.5);
  }
  printf("%lld\n", ans);
  return 0;
}
