#include <bits/stdc++.h>
using namespace std;
long long dp[103][2][4];
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int l = n.size();
  dp[0][0][0] = 1;
  for (int i = 0; i < l; ++i) {
    int D = n[i] - '0';
    for (int smaller = 0; smaller < 2; ++smaller) {
      for (int j = 0; j <= k; ++j) {
        for (int x = 0; x <= (smaller ? 9 : D); ++x) {
          if (x == 0) {
            dp[i + 1][smaller || (x < D)][j] += dp[i][smaller][j];
          } else {
            dp[i + 1][smaller || (x < D)][j + 1] += dp[i][smaller][j];
          }
        }
      }
    }
  }
  cout << dp[l][1][k] + dp[l][0][k] << endl;
  return 0;
}
