#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  long long ans = 0;
  if (k == 1) {
    ans += n[0] - '0';
    int x = n.size() - 1;
    ans += x * 9;
  }
  if (k == 2) {
    int x = n.size() - 1;
    ans += (n[0] - '0' - 1) * x * 9;
    int y = 1;
    while (n[y] - '0' == 0) y++;
    ans += n[y] - '0';
    for (int i = y + 1; i < n.size(); i++) ans += n[i] - '0';
    for (int i = x; i >= 2; i--) {
      ans += (9 * 9 * (i - 1));
    }
  }
  if (k == 3) {
    int x = n.size() - 1;
    ans += (n[0] - '0' - 1) * x * (x - 1) * 81 / 2;
    int y = 1;
    while (n[y] - '0' == 0) y++;
    for (int i = y; i < x; i++) {
      for (int j = i + 1; j <= x; j++) {
        if (i == 1 && j == i + 1 && n[i] - '0' > 0)
          ans += (n[i] - '0' - 1) * 9 + n[j] - '0';
        else
          ans += 9 * 9;
      }
    }
    for (int i = x; i >= 3; i--) {
      for (int j = i - 1; j >= 2; j--) {
        ans += 9 * 9 * 9 * (j - 1);
      }
    }
  }
  cout << ans;
  return 0;
}
