#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
string N;
vector<int> n;
long long dp[100][2][5];
int main() {
  cin >> N;
  int k;
  cin >> k;
  for (auto a : N) {
    n.push_back(a - '0');
  }
  int l = N.size();
  dp[0][0][0] = 1LL;
  for (int i = 0; i < l; i++) {
    for (int smaller = 0; smaller < 2; smaller++) {
      for (int j = 0; j < k + 1; j++) {
        for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
          if (x != 0) {
            dp[i + 1][smaller || x < n[i]][j + 1] += dp[i][smaller][j];
          } else {
            dp[i + 1][smaller || x < n[i]][j] += dp[i][smaller][j];
          }
        }
      }
    }
  }
  cout << dp[l][0][k] + dp[l][1][k] << endl;
  return 0;
}
