#include <bits/stdc++.h>
using namespace std;
string N;
int K, len, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  len = N.length();
  if (K == 1) {
    ans = (len - 1) * 9 + N[0] - '0';
  } else if (K == 2) {
    for (int i = 2; i < len; i++) ans += 81 * (i - 1);
    ans += ((N[0] - '0') * 10 + (N[1] - '0') - 9 -
            ((N[0] - '0') * 10 + (N[1] - '0')) / 10) +
           (N[0] - '0') * 9 * (len - 2);
  } else {
    for (int i = 3; i < len; i++) {
      ans += 729 * (i - 1) * (i - 2) / 2;
    }
    ans += (N[0] - '0' - 1) * 81 * (len - 1) * (len - 2) / 2;
    for (int i = 1; i < len; i++) {
      for (int j = i + 1; j < len; j++) {
        ans += (N[i] - '0') * (N[j] - '0');
      }
    }
  }
  cout << ans << endl;
  return 0;
}
