#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long n = s.length(), k;
  cin >> k;
  long long res = 0;
  if (k == 1) {
    if (n > 1) res = (n - 1) * 9;
    res += s[0] - '0';
  } else if (k == 2) {
    if (n > 2) res = (((n - 1) * (n - 2)) / 2) * 81;
    if (n > 1) {
      res += (s[0] - '0' - 1) * (n - 1) * 9;
      res += (s[1] - '0') + (n - 2) * 9;
    }
  } else {
    if (n > 3) res = (((n - 1) * (n - 2) * (n - 3)) / 6) * 729;
    if (n > 2) {
      res += (s[0] - '0' - 1) * (((n - 1) * (n - 2)) / 2) * 81;
      res += ((n - 2) * (n - 3) / 2) * 81;
      res += (s[1] - '0' - 1) * (n - 2) * 9;
      res += (s[2] - '0') + (n - 3) * 9;
    }
  }
  cout << res;
  return 0;
}
