#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int pattern(int d, int k) {
  if (d < k)
    return 0;
  else if (k <= 0)
    return 1;
  else if (k == 1)
    return 9 * d;
  else if (k == 2)
    return 81 * (d - 1) * d / 2;
  else if (k == 3)
    return 729 * d * (d - 1) * (d - 2) / 6;
}
int number(char ch) {
  if (ch == '0') return 0;
  if (ch == '1') return 1;
  if (ch == '2') return 2;
  if (ch == '3') return 3;
  if (ch == '4') return 4;
  if (ch == '5') return 5;
  if (ch == '6') return 6;
  if (ch == '7') return 7;
  if (ch == '8') return 8;
  if (ch == '9') return 9;
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  ll answer = 0;
  if (n.size() < k) {
    cout << 0 << endl;
    return 0;
  }
  answer += pattern(n.size() - 1, k);
  int left1 = number(n.at(0));
  if (k == 1) {
    answer += pattern(n.size() - 1, k - 1) * left1;
    cout << answer << endl;
    return 0;
  }
  answer += pattern(n.size() - 1, k - 1) * (left1 - 1);
  int left2 = number(n.at(1));
  if (k == 2) {
    answer += (pattern(n.size() - 2, 1) + left2);
    cout << answer << endl;
    return 0;
  }
  answer += pattern(n.size() - 2, 2);
  answer += pattern(n.size() - 2, 1) * (left2 - 1);
  int left3 = number(n.at(2));
  answer += pattern(n.size() - 3, 1) + left3;
  cout << answer << endl;
  return 0;
}
