#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  string second;
  long long k;
  cin >> second >> k;
  long long n = long long((second).size());
  vector<long long> nz(n);
  nz[0] = 1;
  for (long long i = 0; i < long long(n - 1); ++i)
    nz[i + 1] = nz[i] + (second[i] != '0');
  if (k == 1) {
    long long ans = 0;
    for (long long i = 0; i < long long(n); ++i) {
      for (long long j = 1; j <= 9; ++j) {
        if (i != 0 || second[0] - '0' >= j) ++ans;
      }
    }
    cout << ans << '\n';
    return;
  }
  if (k == 2) {
    long long ans = 0;
    for (long long j = 0; j < long long(n); ++j) {
      for (long long i = 0; i < long long(j); ++i) {
        if (i != 0)
          ans += 81;
        else {
          long long fst = second[0] - '0' - 1;
          if (fst > 0) ans += fst * 9;
          fst = second[0] - '0';
          if (nz[j] == nz[i] + 1)
            ans += second[j] - '0';
          else
            ans += 9;
        }
      }
    }
    cout << ans << '\n';
    return;
  }
  long long ans = 0;
  for (long long k = 0; k < long long(n); ++k)
    for (long long j = 0; j < long long(k); ++j)
      for (long long i = 0; i < long long(j); ++i) {
        if (i != 0) {
          ans += 9 * 9 * 9;
          continue;
        }
        if (nz[j] != nz[i] + 1) {
          ans += (second[i] - '0') * 9 * 9;
          continue;
        }
        if (nz[k] != nz[j] + 1) {
          ans += (second[i] - '0') * (second[j] - '0') * 9;
          continue;
        }
        ans += (second[i] - '0') * (second[j] - '0') * (second[k] - '0');
      }
  cout << ans << '\n';
}
signed main() {
  long long T = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(22);
  for (long long i = 1; i <= T; ++i) {
    solve();
  }
  return 0;
}
