#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
bool cmp(int a, int b) { return a > b; }
const long long mod = 1e9 + 7;
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const long double pi = 3.141592653589793;
long long modpow(long long n, long long k, long long mod) {
  if (k == 0) return 1;
  long long r = modpow(n * n % mod, k >> 1, mod);
  if (k & 1) r = r * n % mod;
  return r;
}
const int N = 5e5 + 10;
long long fac[N];
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
void init() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod;
}
long long inv(long long a) { return binpow(a, mod - 2); }
long long A(long long n, long long m) { return fac[n] * inv(fac[n - m]) % mod; }
long long C(long long n, long long m) {
  if (n < m) return 0;
  return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}
void solve() {
  init();
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  if (k == 1) {
    cout << C(n - 1, 1) * 9 + (s[0] - '0');
  } else if (k == 2) {
    if (n < 2) {
      cout << 0;
      return;
    }
    int ans = C(n - 1, 2) * 81;
    for (char c = '1'; c < s[0]; c++) {
      ans += C(n - 1, 1) * 9;
    }
    if (s[1] != '0') ans += C(n - 2, 1) * 9;
    ans += (s[1] - '0');
    cout << ans;
  } else if (k == 3) {
    if (n < 3) {
      cout << 0;
      return;
    }
    int ans = C(n - 1, 3) * 729;
    for (char c = '1'; c < s[0]; c++) {
      ans += C(n - 1, 2) * 81;
    }
    for (char c = '0'; c < s[1]; c++) {
      if (c == '0')
        ans += C(n - 2, 2) * 81;
      else
        ans += C(n - 2, 1) * 9;
    }
    if (s[2] != '0') ans += C(n - 3, 1) * 9;
    ans += (s[2] - '0');
    cout << ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
