#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  if (k == 1) {
    long long ans = 0;
    ans += n[0] - '0';
    ans += (n.size() - 1) * 9;
    cout << ans << endl;
    return 0;
  } else if (k == 2) {
    long long ans = 0;
    bool flag = 0;
    for (int i = 0; i < n.size() - 1; i++)
      for (int j = i + 1; j < n.size(); j++) {
        if (i == 0) {
          if (flag == 1) {
            ans += 9;
          } else {
            ans += (n[j] - '0');
          }
          ans += (n[i] - '1') * 9;
        } else
          ans += 9 * 9;
        if (n[j] != 0) flag = 1;
      }
    cout << ans << endl;
  } else if (k == 3) {
    long long ans = 0;
    bool flag = 0, flag1 = 0;
    for (int i = 0; i < n.size() - 2; i++)
      for (int j = i + 1; j < n.size() - 1; j++)
        for (int kk = j + 1; kk < n.size(); kk++) {
          if (i == 0) {
            if (flag1 == 1 && flag == 1) {
              ans += 9 * 9;
            } else if (flag1 == 1 && flag == 0) {
              ans += 9 * (n[j] - '0');
            } else {
              ans += (n[j] - '0') * (n[kk] - '0');
            }
            ans += (n[i] - '1') * 9 * 9;
          } else {
            ans += 9 * 9 * 9;
          }
          if (n[j] != 0) flag = 1;
          if (n[kk] != 0) flag1 = 1;
        }
    cout << ans << endl;
  }
  return 0;
}
