#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long ret = 0, pos = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') pos = -1, c = getchar();
  while (isdigit(c)) ret = (ret << 3) + (ret << 1) + c - 48, c = getchar();
  return pos * ret;
}
string n;
long long k;
long long ans;
signed main() {
  cin >> n;
  k = read();
  long long len = n.length();
  if (k == 1) {
    ans += 9 * (len - 1);
    ans += (n[0] - '0');
  } else if (k == 2) {
    long long cnt = (len - 1) * (len - 2) / 2 * 81;
    ans += cnt;
    long long l = n[0] - '0', r = n[1] - '0';
    ans += (l - 1) * (len - 1) * 9;
    cnt = (len - 2) * 9 + r;
    ans += cnt;
  }
  cout << ans;
}
