#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long num(long long k, long long x) {
  long long ans = 0;
  if (k == 1)
    ans += (x - 1) * 9;
  else if (k == 2)
    ans += (x - 1) * (x - 2) * 81 / 2;
  else
    ans += (x - 1) * (x - 2) * (x - 3) * 729 / 6;
  return max(ans, (long long)0);
}
int main() {
  string n;
  long long k;
  cin >> n >> k;
  long long x = n.size();
  int s = atoi(n.substr(0, min((long long)3, x)).c_str());
  long long t = (long long)s;
  long long ans = 0;
  ans += num(k, x);
  if (k == 1) {
    if (t >= 100)
      t /= 100;
    else if (t >= 10)
      t /= 10;
    ans += t;
  } else if (k == 2) {
    if (t < 10) {
      cout << 0 << endl;
      return 0;
    }
    if (t >= 100) t /= 10;
    ans += (t / 10 - 1) * num(1, x);
    ans += num(1, x - 1);
    ans += (t % 10);
  } else {
    if (t < 100) {
      cout << 0 << endl;
      return 0;
    }
    ans += (t / 100 - 1) * num(2, x);
    ans += num(2, x - 1);
    ans += max((long long)0, (t % 100) / 10 - 1) * num(1, x - 1);
    ans += num(1, x - 2);
    ans += t % 10;
  }
  cout << ans << endl;
  return 0;
}
