#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
vector<vector<long long> > Comb(int n) {
  vector<vector<long long> > v(n + 1, vector<long long>(n + 1));
  for (int i = 0; i <= n; i++) v[i][i] = v[i][0] = 1LL;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j < i; j++) v[i][j] = v[i - 1][j] + v[i - 1][j - 1];
  }
  return v;
}
void Main() {
  vector<vector<long long> > p = Comb(111);
  string s;
  long long m;
  cin >> s >> m;
  long long ans = 0, c = 0;
  for (long long i = (long long)(0); i < (long long)(s.size()); i++) {
    if (s[i] != '0') {
      if (m - c >= 0) ans += p[s.size() - i - 1][m - c] * pow(9, m - c);
      if (m - c - 1 >= 0)
        ans +=
            p[s.size() - i - 1][m - c - 1] * (s[i] - '1') * pow(9, m - c - 1);
      c++;
    }
  }
  if (c <= m) ans++;
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
