#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using vvl = vector<vl>;
constexpr int MOD = 1000000007;
using long long = long long;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long long N;
  int K;
  cin >> N >> K;
  string sN = to_string(N);
  int keta = sN.length();
  vector<vector<int>> dp1(keta, vector<int>(K + 1, 0));
  vector<vector<int>> dp2(keta, vector<int>(K + 1, 0));
  dp1[0][0] = 1;
  dp1[0][1] = sN[0] - '0' - 1;
  dp2[0][1] = 1;
  dp2[0][0] = 0;
  for (int i = 1; i < keta; i++) {
    for (int j = 0; j <= K; j++) {
      if (j == 0) {
        dp1[i][j] = dp1[i - 1][j];
      } else {
        dp1[i][j] = 9 * dp1[i - 1][j - 1] + dp1[i - 1][j];
        if (sN[i] != '0') {
          dp1[i][j] = (sN[i] - '0') * dp2[i - 1][j - 1] + dp2[i - 1][j];
        }
        if (sN[i] == '0') {
          dp2[i][j] = dp2[i - 1][j];
        } else {
          dp2[i][j] = dp2[i][j - 1];
        }
      }
    }
  }
  cout << dp2[keta - 1][K] + dp1[keta - 1][K] << endl;
  return 0;
}
