#include <bits/stdc++.h>
using namespace std;
char a[101];
int num[101];
long long k, sum;
int main() {
  cin >> a >> k;
  int alen = strlen(a);
  for (int i = 0; i < alen; i++) num[i] = a[i] - '0';
  if (k == 1) {
    cout << 9 * (alen - 1) + num[0] << endl;
  } else if (k == 2) {
    for (int i = 2; i < alen; i++) sum += 81 * (i - 1);
    sum += 9 * (num[0] - 1) * (alen - 1);
    int now = 0;
    for (int i = 1; i < alen; i++) {
      now = i;
      if (num[i] != 0) break;
    }
    cout << sum + 9 * (alen - now - 1) + num[now] << endl;
  } else {
    for (int i = 3; i < alen; i++) sum += (i - 1) * (i - 2) / 2 * 729;
    sum += 81 * (num[0] - 1) * (alen - 1) * (alen - 2) / 2;
    int now = 0, noww;
    for (int i = 1; i < alen; i++) {
      now = i;
      if (num[i] != 0) break;
    }
    sum += 81 * (alen - now - 1) * (alen - now - 2) / 2;
    noww = num[now];
    for (int i = now + 1; i < alen; i++) {
      now = i;
      if (num[i] != 0) break;
    }
    cout << sum + (noww - 1) * (9 * (alen - now)) +
                9 * max(0, (alen - now - 1)) + num[now]
         << endl;
  }
  return 0;
}
