#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int sz = s.size();
  vector<int> num(sz);
  for (int i = 0; i < sz; ++i) num[i] = s[i] - '0';
  long long int dp[200][2][k + 2];
  dp[0][0][0] = 1;
  for (long long int i = 0; i < sz; ++i)
    for (long long int smaller = 0; smaller < 2; ++smaller)
      for (long long int j = 0; j < 4; ++j)
        for (int x = 0; x <= (smaller ? 9 : num[i]); ++x)
          dp[i + 1][smaller || x < num[i]][j + (x != 0)] += dp[i][smaller][j];
  cout << dp[sz][0][k] + dp[sz][1][k] << endl;
  return 0;
}
