#include <bits/stdc++.h>
using namespace std;
int f[105][4];
string s;
int a[105];
int sz;
int search(int st, int k) {
  if (f[st][k] >= 0) return f[st][k];
  int ans = 0;
  int n = sz - st;
  if (n < k) {
    return 0;
  } else if (a[st] == 0) {
    ans = search(st + 1, k);
  } else if (k == 1) {
    ans = a[st] + 9 * (n - 1);
  } else if (k == 2) {
    ans = 9 * (a[st] - 1) * (n - 1) + search(st + 1, 1) + search(st + 1, 2);
  } else if (k == 3) {
    ans = 81 * (a[st] - 1) * (n - 1) * (n - 2) / 2 + search(st + 1, 2) +
          search(st + 1, 3);
  }
  return f[st][k] = ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  sz = s.size();
  memset(f, -1, sizeof(f));
  for (int i = 0; i < sz; ++i) a[i] = s[i] ^ 48;
  int k;
  cin >> k;
  cout << search(0, k) << endl;
  return 0;
}
