#include <bits/stdc++.h>
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int k;
  cin >> k;
  long long sum = 0;
  int n = (int)s.size();
  if (n > 1 && k == 1) {
    sum += 9;
  }
  for (long long i = 2; i < n; ++i) {
    if (k == 1) sum += 9;
    if (k == 2) {
      for (int z = 2; z <= i; ++z) {
        sum += 9 * 9;
      }
    }
    if (k == 3) {
      for (int z = 2; z <= i; ++z) {
        for (int j = z + 1; j <= i; ++j) {
          sum += 9 * 9 * 9;
        }
      }
    }
  }
  if (k == 1) sum += s[0] - '0';
  if (k == 2) {
    for (int i = 1; i < n; ++i) sum += (s[0] - '0' - 1) * 9;
    sum += (s[0] - '0' - 1) * (n - 1) * 9;
    for (int i = 1; i < n; ++i) {
      sum += (s[i] - '0');
    }
  }
  if (k == 3) {
    for (int i = 1; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        sum += (s[0] - '0' - 1) * 9 * 9;
      }
    }
    for (int i = 1; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        sum += (s[i] - '0') * (s[j] - '0');
      }
    }
  }
  cout << sum << '\n';
  if (false)
    cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC
         << " sec" << endl;
}
