#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long k, ans = 0;
  cin >> k;
  long long nagasa = s.length();
  if (k == 1) {
    long long x = s[0] - '0';
    ans += x;
    ans += (nagasa - 1) * 9;
  }
  if (k == 2) {
    long long now = nagasa;
    for (long long i = 1; i < nagasa; i++) {
      if (s[i] != '0') {
        now = i;
        break;
      }
    }
    for (long long i = now; i < nagasa; i++) {
      if (i == now)
        ans += s[i] - '0';
      else
        ans += 9;
    }
    long long x = s[0] - '0';
    ans += (x - 1) * (nagasa - 1) * 9;
    ans += (nagasa - 1) * (nagasa - 2) * 81 / 2;
  }
  if (k == 3) {
    long long now = nagasa;
    long long now2 = -1;
    for (long long i = 1; i < nagasa; i++) {
      if (s[i] != '0') {
        now = i;
        break;
      }
    }
    for (long long i = now + 1; i < nagasa; i++) {
      if (s[i] != '0') {
        now2 = i;
        break;
      }
    }
    if (now2 != -1) {
      for (long long i = now2; i < nagasa; i++) {
        if (i == now2)
          ans += s[i] - '0';
        else
          ans += 9;
      }
      ans += 81 * (nagasa - now) * (nagasa - now - 1) / 2;
      long long y = s[now] - '0';
      ans -= (10 - y) * 9 * (nagasa - now - 1);
    }
    long long x = s[0] - '0';
    ans += (x - 1) * (nagasa - 1) * (nagasa - 2) * 81 / 2;
    ans += 9 * 9 * 9 * (nagasa - 1) * (nagasa - 2) * (nagasa - 3) / 6;
  }
  cout << ans << endl;
  return 0;
}
