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