#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long K, ans = 0;
string S;
int main() {
  cin >> S >> K;
  if (K == 1) {
    ans += S[0] - '0';
    ans += 9 * (S.size() - 1);
  } else if (K == 2) {
    ans += (S.size() - 1) * (S.size() - 2) / 2 * 9 * 9;
    ans += (S[0] - '0' - 1) * (S.size() - 1) * 9;
    for (int i = (int)(1); i < (int)(S.size()); i++) {
      if (S[i] != '0') {
        ans += S[i] - '0' + (S.size() - i - 1) * 9;
        break;
      }
    }
  } else {
    ans += (S.size() - 1) * (S.size() - 2) * (S.size() - 3) / 6 * 9 * 9 * 9;
    ans += (S[0] - '0' - 1) * (S.size() - 1) * (S.size() - 2) / 2 * 9 * 9;
    for (int i = (int)(1); i < (int)(S.size() - 1); i++) {
      if (S[i] != '0') {
        for (int j = (int)(i + 1); j < (int)(S.size()); j++) {
          if (S[j] != '0') {
            ans += (S[j] - '0') + (S.size() - j - 1) * 9;
            break;
          }
        }
        ans += (S.size() - i - 1) * (S.size() - i - 2) / 2 * 9 * 9;
        break;
      }
    }
  }
  cout << ans << endl;
}
