#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chkmin(T1 &x, T2 y) {
  return y < x ? (x = y, true) : false;
};
template <typename T1, typename T2>
inline bool chkmax(T1 &x, T2 y) {
  return y > x ? (x = y, true) : false;
};
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long long N = 201;
long long a[N];
long long c[N][N];
long long p[N];
long long get(long long n, long long k) {
  if (k < 0) return 0;
  if (k > n) return 0;
  return c[n][k] * p[k];
}
signed main() {
  fast();
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long kk = k;
  long long ans = 0;
  for (long long i = 0; i < N; i++) c[i][0] = c[i][i] = 1;
  p[0] = 1;
  for (long long i = 1; i < N; i++) p[i] = p[i - 1] * 9;
  for (long long i = 2; i < N; i++) {
    for (long long j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == 0) continue;
    if (s[i] > '1') {
      ans += (s[i] - '1') * get(s.size() - i - 1, kk - 1);
    }
    if (s[i] > '0') ans += get(s.size() - i - 1, kk);
    kk--;
  }
  long long cnt = 0;
  for (long long i = 0; i < s.size(); i++)
    if (s[i] > '0') cnt++;
  if (cnt == k) ans++;
  cout << ans;
  return 0;
}
