#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<int> count_k(string x) {
  vector<int> count;
  for (int i = 0; i < (x.size()); ++i) {
    count.push_back(int(x[x.size() - 1 - i] - '0'));
  }
  return count;
}
int choose(int n, int k) {
  int res = 1;
  for (int i = 0; i < (k); ++i) {
    res *= n;
    n--;
  }
  for (int i = 0; i < (k); ++i) {
    res /= (k - i);
  }
  return res;
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  vector<int> N;
  N = count_k(n);
  int G[N.size()][4];
  for (int i = 0; i < (N.size()); ++i) {
    for (int j = 1; j <= 3; ++j) {
      if (j == 1) {
        G[i][j] = N[i] + 9 * i;
      }
      if (j == 2) {
        if (i == 0) {
          G[i][j] = 0;
          continue;
        }
        G[i][j] =
            choose(i, 2) * 81 + choose(i, 1) * 9 * (N[i] - 1) + G[i - 1][1];
      }
      if (j == 3) {
        if (i == 0) {
          G[i][j] = 0;
          continue;
        }
        G[i][j] = choose(i, 3) * 81 * 9 + choose(i, 2) * 81 * (N[i] - 1) +
                  G[i - 1][2];
      }
    }
  }
  cout << G[N.size() - 1][k] << endl;
}
