#include <bits/stdc++.h>
using namespace std;
long long f1(string s) {
  long long n = s.size();
  if (n <= 0) return 0;
  return (s[0] - '0') + (n - 1) * 9;
}
long long f2(string s) {
  long long n = s.size();
  if (n <= 1) return 0;
  long long p1 = ((n - 1) * (n - 2) * 9 * 9) / 2;
  long long p2 = (s[0] - '1') * (n - 1) * 9;
  string t = s;
  t.erase(t.begin());
  long long p3 = f1(t);
  return p1 + p2 + p3;
}
long long f3(string s) {
  long long n = s.size();
  if (n <= 2) return 0;
  long long p1 = ((n - 1) * (n - 2) * (n - 3) * 9 * 9 * 9) / 6;
  long long p2 = (s[0] - '1') * ((n - 1) * (n - 2) * 9 * 9) / 2;
  string t = s;
  t.erase(t.begin());
  long long p3 = f2(t);
  return p1 + p2 + p3;
}
int main() {
  string st;
  int k;
  cin >> st >> k;
  long long ans;
  if (k == 1) ans = f1(st);
  if (k == 2) ans = f2(st);
  if (k == 3) ans = f3(st);
  cout << ans << endl;
  return 0;
}
