#include <bits/stdc++.h>
using namespace std;
int nCr(int n, int r) {
  int num = 1;
  for (int i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int nl = n.size();
  int a = 0;
  if (k == 1) {
    a += nCr(nl - 1, k) * pow(9, k);
    a += (n[0] - '0');
  } else if (k == 2) {
    a += nCr(nl - 1, k) * pow(9, k);
    a += (n[0] - '1') * (nl - 1) * 9;
    a += (n[1] - '0') + (nl - 2) * 9;
  } else if (k == 3) {
    a += nCr(nl - 1, k) * pow(9, k);
    a += nCr(nl - 1, k - 1) * pow(9, k - 1) * (n[1] - '1');
    if (n[1] != '0') a += nCr(nl - 2, k - 2) * pow(9, k - 2) * (n[1] - '1');
    a += nCr(nl - 2, 2) * pow(9, 2);
    a += (n[2] - '0') + (nl - 3) * 9;
  }
  cout << a;
}
