#include <bits/stdc++.h>
using namespace std;
template <class T>
using arr = vector<vector<T>>;
template <class T>
int popcount(T &a) {
  int c = 0;
  for (int i = 0; i < (8 * (int)sizeof(a)); i++) {
    if ((a >> i) & 1) c++;
  }
  return c;
}
template <class T>
void pr(T x) {
  cout << x << endl;
}
template <class T>
void prvec(vector<T> &a) {
  for (int i = 0; i < (a.size() - 1); i++) {
    cout << a[i] << " ";
  }
  pr(a[a.size() - 1]);
}
template <class T>
void prarr(arr<T> &a) {
  for (int i = 0; i < (a.size()); i++)
    if (a[i].empty())
      pr("");
    else
      prvec(a[i]);
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int keta = s.size();
  if (k > keta) {
    pr(0);
    return 0;
  }
  int d[101][4] = {};
  for (int i = 1; i < (101); i++) {
    for (int j = 1; j < (4); j++) {
      if (j == 1)
        d[i][j] = 9;
      else {
        int sec, thi;
        if (j > i) continue;
        if (j == 2) d[i][j] = 9 * (i - 1) * 9;
        if (j == 3) d[i][j] = 9 * (i - 1) * (i - 2) * 9 * 9 / 2;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < (keta); i++) ans += d[i][k];
  int a, b, c;
  a = s[0] - '0';
  if (keta >= 2) b = s[1] - '0';
  if (keta >= 3) c = s[2] - '0';
  if (k == 1) {
    ans += a;
    pr(ans);
    return 0;
  }
  if (k == 2) {
    ans += a * (keta - 2) * 9;
    ans += (a - 1) * 9 + b;
    pr(ans);
    return 0;
  }
  if (k == 3) {
    ans += a * (keta - 2) * (keta - 3) * 9 * 9 / 2;
    int sec = 0;
    sec += (a - 1) * 9 * 9;
    sec += b * 9;
    sec *= keta - 3;
    ans += sec;
    sec = 0;
    sec += (a - 1) * 9 * 9;
    if (b > 0) sec += (b - 1) * 9;
    sec += c;
    ans += sec;
    pr(ans);
    return 0;
  }
  return 0;
}
