#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
long long num[109];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i = 0; i < S.size(); i++) num[i] = (S[i] - '0');
  long long N = long long(S.size());
  long long ans = 0;
  if (K == 3) {
    ans += (num[0] - 1) * (N - 1) * (N - 2) / 2 * 81;
    ans += (N - 1) * (N - 2) * (N - 3) / 6 * 9 * 9 * 9;
    ans += (num[1] - 1) * (N - 2) * 9;
    ans += (N - 2) * 9 - (9 - num[2]);
    ans += (N - 2) * (N - 3) / 2 * 81;
  }
  if (K == 2) {
    ans += (num[0] - 1) * (N - 1) * 9;
    ans += (N - 1) * (N - 2) / 2 * 81;
    ans += (N - 1) * 9 - (9 - num[1]);
  }
  if (K == 1) {
    ans += N * 9 - (9 - num[0]);
  }
  cout << ans << endl;
  return 0;
}
