#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
long long dfs(string S, int K) {
  int N = S.size();
  if (N == 1) {
    if (K == 1) {
      return S.at(0) - '0';
    } else {
      return 0;
    }
  }
  if (K == 0) {
    return 1;
  }
  long long zeroans;
  long long ans;
  if (K == 3) {
    zeroans = (N - 1) * (N - 2) * (N - 3) * 729 / 6;
    ans = (N - 1) * (N - 2) * 81 / 2;
  } else if (K == 2) {
    zeroans = (N - 1) * (N - 2) * 81 / 2;
    ans = (N - 1) * 9;
  } else {
    zeroans = (N - 1) * 9;
    ans = 1;
  }
  return zeroans + ans * ((S.at(0) - '0') - 1) + dfs(S.substr(1), K - 1);
}
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  cout << dfs(S, K) << endl;
}
