#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 1e18;
long long int solve(string s, long long int k) {
  long long int n = s.size();
  long long int m = 0;
  if (k == 1) {
    m += (n - 1) * 9;
    long long int b = s[0] - '0';
    m += b;
  } else if (k == 2) {
    if (n <= 1) {
      return 0;
    } else if (n == 2) {
      if (s == "10") return 0;
    }
    m += (n - 1) * (n - 2) / 2 * 9 * 9;
    long long int b = s[0] - '0';
    m += (b - 1) * (n - 1) * 9;
    string t = s.substr(1);
    m += solve(t, 1);
  } else {
    if (n <= 2) {
      return 0;
    } else if (n == 3) {
      if (s <= "110") return 0;
    }
    m += (n - 1) * (n - 2) * (n - 3) / 6 * 9 * 9 * 9;
    long long int b = s[0] - '0';
    m += (b - 1) * (n - 1) * (n - 2) / 2 * 9 * 9;
    string t = s.substr(1);
    m += solve(t, 2);
  }
  return m;
}
int main() {
  string s;
  long long int k;
  cin >> s >> k;
  cout << solve(s, k) << endl;
}
