#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  int k;
  cin >> n >> k;
  int i, l;
  vector<int> num(100, 0);
  int j = 0;
  for (i = n.size() - 1; i >= 0; i--) {
    num.at(j) = n.at(i) - '0';
    j++;
  }
  int maxdig = j - 1;
  if (k == 1) {
    cout << maxdig * 9 + num.at(maxdig) << endl;
  } else if (k == 2) {
    int ans = 0;
    bool jok = false;
    for (i = maxdig; i >= 0; i--) {
      for (j = i - 1; j >= 0; j--) {
        if (i < maxdig) {
          ans += 9 * 9;
          continue;
        } else if (jok) {
          ans += num.at(i) * 9;
          continue;
        }
        int a, b;
        a = 1;
        b = 1;
        while (a < num.at(i)) {
          ans += 9;
          a++;
        }
        while (b <= num.at(j)) {
          ans++;
          b++;
        }
        if (num.at(j) > 0) jok = true;
      }
    }
    cout << ans << endl;
  } else {
    int ans = 0;
    bool jok = false;
    for (i = maxdig; i >= 0; i--) {
      for (j = i - 1; j >= 0; j--) {
        bool lok = false;
        for (l = j - 1; l >= 0; l--) {
          if (i < maxdig) {
            ans += 9 * 9 * 9;
            continue;
          } else if (jok) {
            ans += num.at(i) * 9 * 9;
            continue;
          } else if (lok) {
            ans += (num.at(i) - 1) * 9 * 9 + num.at(j) * 9;
            continue;
          }
          int a, b, c;
          a = 1;
          b = 1;
          c = 1;
          while (a < num.at(i)) {
            ans += 9 * 9;
            a++;
          }
          while (b < num.at(j)) {
            ans += 9;
            b++;
          }
          while (c <= num.at(k)) {
            ans++;
            c++;
          }
          if (num.at(l) > 0) lok = true;
        }
        if (num.at(j) > 0) jok = true;
      }
    }
    cout << ans << endl;
  }
}
