#include <bits/stdc++.h>
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int siz = (int)s.size();
  int fi = s[0] - '0';
  if (siz < k) {
    cout << 0 << endl;
    return 0;
  }
  if (siz == 1) {
    cout << fi << endl;
    return 0;
  }
  int se = s[1] - '0';
  long long ans = 0;
  if (k == 1) {
    ans += 9 * (siz - 1) + fi;
    cout << ans << endl;
  } else if (k == 2) {
    if (siz == 2) {
      ans += 9 * (fi - 1) + se;
      cout << ans << endl;
      return 0;
    }
    ans += (siz - 1) * (siz - 2) / 2 * 9 * 9;
    ans += (siz - 2) * 9 * fi;
    ans += (fi - 1) * 9 + se;
    cout << ans << endl;
  } else {
    int th = s[2] - '0';
    if (siz == 3) {
      ans += (fi - 1) * 9 * 9;
      ans += (se - 1) * 9 + th;
      cout << ans << endl;
      return 0;
    }
    ans += (siz - 1) * (siz - 2) * (siz - 3) / 6 * 9 * 9 * 9;
    ans += (siz - 2) * (siz - 3) / 2 * 9 * 9 * fi;
    ans += (siz - 3) * 9 * fi * se;
    ans += (fi - 1) * 9 * 9;
    ans += (se - 1) * 9 + th;
    cout << ans << endl;
  }
  return 0;
}
