#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
const long long int INF = 1e15;
const long long int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;
long long int func(long long int num, long long int k) {
  long long int a = 1;
  long long int b = 1;
  for (long long int i = 1; i <= k; i++) {
    a *= i;
    b *= num + 1 - i;
  }
  return b / a;
}
signed main() {
  string N;
  long long int K;
  cin >> N >> K;
  if (K == 2 && N.size() <= 1) {
    cout << 0;
    return 0;
  } else if (K == 3 && N.size() <= 2) {
    cout << 0;
    return 0;
  }
  long long int num = N.size() - 1;
  long long int ans = func(num, K) * pow(9, K);
  if (K == 1) {
    long long int top1 = N[0] - '0';
    ans += top1;
    cout << ans;
  } else if (K == 2) {
    long long int top1 = N[0] - '0';
    long long int top2;
    ans += (top1 - 1) * func(num, 1) * 9;
    long long int cnt = 0;
    for (long long int i = 1; i < N.size(); i++) {
      if (N[i] == '0')
        cnt++;
      else {
        top2 = N[i] - '0';
        break;
      }
    }
    ans += 9 * max((num - 1 - cnt), 0ll) + top2;
    cout << ans;
  } else {
    long long int top1 = N[0] - '0';
    long long int top2 = N[1] - '0';
    long long int top3;
    ans += (top1 - 1) * func(num, 2) * pow(9, 2);
    ans += (top2 - 1) * func(num - 1, 1) * 9;
    if (top2 != 0) ans += func(num - 1, 2) * pow(9, 2);
    long long int cnt = 0;
    for (long long int i = 2; i < N.size(); i++) {
      if (N[i] == '0')
        cnt++;
      else {
        top3 = N[i] - '0';
        break;
      }
    }
    ans += 9 * max((num - 2 - cnt), 0ll) + top3;
    cout << ans;
  }
}
