#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, K;
  cin >> N >> K;
  string s = to_string(N);
  long long dp[105][2][4];
  for (long long i = 0; i < (105); i++) {
    for (long long smaller = 0; smaller < (2); smaller++) {
      for (long long k = 0; k < (2); k++) {
        dp[i][smaller][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (long long i = 0; i < (s.size()); i++) {
    for (long long smaller = 0; smaller < (2); smaller++) {
      for (long long k = 0; k < (4); k++) {
        int c_ = s[i] - '0';
        for (long long c = 0; c < (10); c++) {
          int i_ = i + 1;
          int smaller_ = smaller;
          int k_ = k;
          if (c != 0) {
            k_++;
          }
          if (k_ > K) {
            continue;
          }
          if (smaller_ == 0) {
            if (c_ < c) {
              continue;
            } else if (c < c_) {
              smaller_ = 1;
            }
          }
          dp[i_][smaller_][k_] += dp[i][smaller][k];
        }
      }
    }
  }
  cout << dp[s.size()][0][K] + dp[s.size()][1][K] << endl;
}
