#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ll N, K;
  cin >> N;
  cin >> K;
  int max_order = log10(N) + 1;
  ll ans = 0;
  for (int i = 1; i < max_order; i++) {
    if (i < K) continue;
    ll num = 9;
    if (K == 2) {
      num *= (i - 1) * 9;
    } else if (K == 3) {
      num *= (i - 1) * (i - 2) * 81;
    }
    ans += num;
  }
  int a0 = N / pow(10, max_order - 1);
  int N2 = N - a0 * pow(10, max_order - 1);
  int next_order = log10(N2) + 1;
  int a_next = N2 / pow(10, next_order - 1);
  if (K == 2) {
    ll num = (a0 - 1) * (max_order - 1) * 9;
    ll num2 = (next_order - 1) * 9;
    num2 += a_next;
    num += num2;
    ans += num;
  }
  if (K == 3) {
    ll num = (a0 - 1) * (max_order - 1) * (max_order - 2) * 81;
    ll num2 = (next_order - 1) * (next_order - 2) * 81;
    num2 += a_next * (next_order - 1) * 9;
    num += num2;
    ans += num;
  }
  cout << ans << endl;
  return 0;
}
