#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  int ans = 0;
  if (K == 1) {
    ans += (N.size() - 1) * 9;
    ans += N[0] - '0';
  } else if (K == 2) {
    for (int i = 2; i < N.size(); i++) {
      ans += 9 * (i - 1) * 9;
    }
    ans += 9 * (N.size() - 1) * (N[0] - '1');
    string M = "";
    M += N[0];
    for (int j = 1; j < N.size(); j++) M += '0';
    string num[9] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
    for (int k = N.size() - 1; k >= 1; k--) {
      for (int n = 0; n < 9; n++) {
        string M_change = M;
        M_change.replace(k, k, num[n]);
        if (M_change <= N) ans++;
      }
    }
  } else {
    for (int i = 3; i < N.size(); i++) {
      int a = 81 * 9 * i * (i - 1);
      a /= 2;
      ans += a;
    }
    int b = 81 * (N[0] - '1') * (N.size() - 1) * (N.size() - 2);
    b /= 2;
    ans += b;
    string M = "";
    M += N[0];
    for (int j = 1; j < N.size(); j++) M += '0';
    string num[9] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
    for (int k = N.size() - 1; k >= 3; k--) {
      for (int n = 0; n < 9; n++) {
        for (int l = k - 1; l >= 2; l--) {
          for (int m = 0; m < 9; m++) {
            string M_change = M;
            M_change.replace(k, k, num[n]);
            M_change.replace(l, l, num[m]);
            if (M_change <= N) ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
