#include <bits/stdc++.h>
using namespace std;
int64_t POW(int64_t x, int64_t y) {
  int64_t res = 1;
  for (int64_t i = 0; i < y; ++i) {
    res = res * x;
  }
  return res;
}
int64_t COM(int64_t x, int64_t y) {
  int64_t res = 1;
  int64_t res2 = 1;
  for (int64_t i = 0; i < y; ++i) {
    res = res * (x - i);
  }
  for (int64_t i = 0; i < y; ++i) {
    res2 = res2 * (i + 1);
  }
  return res / res2;
}
int main() {
  string N;
  int64_t K;
  cin >> N >> K;
  int64_t n = N.size();
  int64_t num = 0;
  if (n < 4) {
    int64_t intN = stoi(N);
    for (int64_t i = 1; i < 1000; ++i) {
      if (i > intN) break;
      string sti = to_string(i);
      int count = 0;
      for (int64_t j = 0; j < sti.size(); ++j) {
        if (sti[j] != '0') ++count;
      }
      if (count == K) ++num;
    }
  } else {
    int64_t N0, N1, N2;
    N0 = N[0] - '0';
    N1 = N[1] - '0';
    N2 = N[2] - '0';
    if (K == 3) {
      num = num + (N0 - 1) * COM(n - 1, 2) * POW(9, 2);
      num = num + COM(n - 1, 3) * POW(9, 3);
      num = num + (N1 - 1) * COM(n - 2, 1) * POW(9, 1);
      num = num + COM(n - 2, 2) * POW(9, 2);
      num = num + (N2 - 1);
      num = num + COM(n - 3, 1) * POW(9, 1);
    } else if (K == 2) {
      num = num + (N0 - 1) * COM(n - 1, 1) * POW(9, 1);
      num = num + COM(n - 1, 2) * POW(9, 2);
      num = num + (N1 - 1);
      num = num + COM(n - 2, 1) * POW(9, 1);
    } else if (K == 1) {
      num = num + (N0 - 1);
      num = num + COM(n - 1, 1) * POW(9, 1);
    }
    ++num;
  }
  cout << num << endl;
  return 0;
}
