#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n == 1) return (a % 1000000007);
  long long int hanbun = n / 2;
  long long int amari = n % 2;
  long long int ans = (a * a) % 1000000007;
  ans = modpow(ans, hanbun);
  if (amari == 1) ans *= a;
  ans %= 1000000007;
  return ans;
}
long long int gcd(long long int a, long long int b) {
  if (a < b) {
    long long int tmp = a;
    a = b;
    b = tmp;
  }
  long long int amari = a % b;
  if (amari == 0) return b;
  return gcd(b, amari);
}
long long int lcm(long long int a, long long int b) {
  long long int ans = (a * b) % 1000000007;
  long long int wari = modpow(gcd(a, b), 1000000007 - 2);
  ans = (ans * wari) % 1000000007;
  return ans;
}
long long int factElement[10000] = {0};
long long int factrial(int n) {
  if (factElement[n] != 0) return factElement[n];
  if (n == 0) {
    factElement[0] = 1;
    return factElement[n];
  }
  long long int ans = n * factrial(n - 1);
  factElement[n] = ans;
  return factElement[n];
}
bool atama = false;
bool sita = false;
long long int solveE(string str, int k, bool atama, bool ketu) {
  if (k == 0) return 1;
  if (k > str.size()) return 0;
  long long int ans = 0;
  string tail = str.substr(1);
}
long long int solve(string str, int k, bool flg) {
  if (k == 0) return 1;
  if (str.size() < k) return 0;
  string tail = str.substr(1);
  int head = str[0] - '0';
  long long int ans = 0;
  if (flg) {
    ans += solve(tail, k, flg);
    ans += 9 * solve(tail, k - 1, flg);
  } else {
    if (head != 0) ans += solve(tail, k - 1, false);
    ans += solve(tail, k, true);
    if (head != 0) {
      ans += (head - 1) * solve(tail, k - 1, true);
    }
  }
  return ans;
}
int main() {
  string str;
  cin >> str;
  int k;
  cin >> k;
  long long int ans = 0;
  if (k == 1) {
    ans = str[0] - '0';
    ans += 9 * (str.size() - 1);
    cout << ans << endl;
    return 0;
  } else {
    ans = solve(str, k, false);
  }
  cout << ans << endl;
  return 0;
}
