#include <bits/stdc++.h>
using namespace std;
void run_case() {
  string str;
  int K;
  cin >> str >> K;
  int siz = str.size();
  long long ans = 0;
  if (K == 1 && siz >= 1) {
    int top = str[0] - '0';
    for (int i = 1; i < siz; ++i) ans += 9;
    ans += top;
  } else if (K == 2 && siz >= 2) {
    int top = str[0] - '0';
    for (int i = 2; i < siz; ++i) ans += 9 * (9 * (i - 1));
    ans += (top - 1) * 9 * (siz - 1);
    ans += (str[1] - '0' - 1) + 9 * (siz - 2) + 1;
  } else if (K == 3 && siz >= 3) {
    for (int i = 3; i < siz; ++i) ans += 9 * (i - 1) * (i - 2) / 2 * 81;
    ans += (str[0] - '0' - 1) * (siz - 1) * (siz - 2) / 2 * 81;
    ans += (str[1] - '0' - 1) * (siz - 2) * 9 + (siz - 2) * (siz - 3) / 2 * 81;
    ans += (str[2] - '0' - 1) + (siz - 3) * 9 + 1;
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  run_case();
  cout.flush();
  return 0;
}
