#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int l = n.size();
  long long ans = 0;
  if (k == 1) {
    ans += (l - 1) * 9;
    string a{n[0]};
    istringstream s = istringstream(a);
    int num;
    s >> num;
    ans += num;
  } else if (k == 2) {
    ans += (l - 1) * (l - 2) * 81 / 2;
    string a{n[0]};
    string b{n[1]};
    istringstream s = istringstream(a);
    istringstream t = istringstream(b);
    int x;
    int y;
    s >> x;
    t >> y;
    ans += 10 * x + y - 9 - x;
    ans += x * (l - 2) * 9;
  } else {
    ans += 729 * (l - 1) * (l - 2) * (l - 3) / 6;
    string x{n[0]};
    string y{n[1]};
    string z{n[2]};
    istringstream s = istringstream(x);
    istringstream t = istringstream(y);
    istringstream u = istringstream(z);
    int a;
    int b;
    int c;
    s >> a;
    t >> b;
    u >> c;
    ans += 100 * a + 10 * b + c - 99;
    ans -= 18 * a;
    ans -= b;
    if (b == 0) ans -= 10;
    if (c == 0) ans -= 1;
    ans += a * 81 * (l - 2) * (l - 3) / 2;
  }
  cout << ans << endl;
}
