#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  long long K;
  cin >> s >> K;
  long long keta = s.size();
  if (K == 1) {
    long long ans = 9 * (keta - 1);
    long long tt = s[0] - '0';
    ans += tt;
    cout << ans << endl;
  }
  if (K == 2) {
    long long ans = 0;
    for (long long i = 2; i < keta; i++) {
      ans += 9 * (i - 1) * 9;
    }
    long long tt = s[0] - '0';
    ans += (tt - 1) * (keta - 1) * 9;
    long long m_l = 0;
    for (long long i = 1; i < s.size(); i++) {
      if (m_l == 0 && s[i] - '0' != 0) {
        ans += s[i] - '0';
        m_l = 1;
      } else if (m_l == 1) {
        ans += 9;
      }
    }
    cout << ans << endl;
  }
  if (K == 3) {
    return 0;
    long long ans = 0;
    for (long long i = 3; i < keta; i++) {
      ans += 9 * 9 * 9 * (i - 1) * (i - 2) / 2;
    }
    long long tt = s[0] - '0';
    ans += (tt - 1) * (keta - 1) * 9 * (keta - 2) * 9 / 2;
    long long kata[120] = {0};
    long long mm = 0;
    long long jm[2];
    jm[0] = -1;
    jm[1] = -1;
    for (long long i = 1; i < s.size(); i++) {
      if (mm < 2 && s[i] - '0' != 0) {
        jm[mm] = i;
        mm++;
        kata[i] = s[i] - '0';
      } else if (mm >= 2) {
        kata[i] = 9;
      }
    }
    if (jm[1] != -1) {
      ans += (keta - jm[1] - 1) * 9 * (keta - jm[1] - 2) * 9 / 2;
      ans += kata[jm[0]] * (keta - jm[1] - 1) * 9;
      ans += kata[jm[1]] * (keta - jm[1] - 1) * 9;
      ans += kata[jm[1]] * kata[jm[0]];
    }
    cout << ans << endl;
  }
}
