#include <bits/stdc++.h>
const int maxn = 100010;
const int inf = 1e9;
const unsigned long long mod = 998244353;
const double pi = 3.14159265358979;
const double ep = 0.0;
using namespace std;
int main() {
  string s;
  int k, ans = 0;
  cin >> s >> k;
  int n = s.size();
  if (n > 1) {
    if (k == 1)
      ans += (n - 1) * 9;
    else if (k == 2)
      ans += (n - 1) * (n - 2) / 2 * 9 * 9;
    else
      ans += (n - 1) * (n - 2) * (n - 3) / 6 * 9 * 9 * 9;
  }
  if (k == 1) ans += s[0] - '0';
  if (k == 2) {
    ans += (s[0] - '1') * (n - 1) * 9;
    ans += (s[1] - '0') + (n - 2) * 9;
  }
  if (k == 3) {
    ans += (s[0] - '1') * (n - 1) * (n - 2) / 2 * 9 * 9;
    ans += (s[1] - '1') * (n - 2) * 9;
    ans += (n - 2) * (n - 3) / 2 * 9 * 9;
  }
  cout << ans << '\n';
  return 0;
}
