#include <bits/stdc++.h>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int Cin() {
  int n;
  cin >> n;
  return n;
}
int main() {
  string N;
  int K;
  cin >> N >> K;
  LLONG digit = N.length();
  vector<LLONG> nums(digit);
  for (int i = 0; i < digit; ++i) {
    nums[i] = N[i] - '0';
  }
  LLONG ans = 0;
  if (K == 1) {
    ans = nums[0] + 9 * (digit - 1);
  } else if (K == 2 && digit >= 2) {
    ans += (nums[0] - 1) * 9 * (digit - 1);
    int nonZero = 0;
    for (int i = 1; i < digit; ++i) {
      if (nums[i] != 0) {
        nonZero = i;
        break;
      }
    }
    if (nonZero > 0) {
      ans += nums[nonZero] + 9 * (digit - 1 - nonZero);
    }
    if (digit > 2) {
      ans += 81 * (digit - 1) * (digit - 2) / 2;
    }
  } else if (K == 3 && digit >= 3) {
    ans += (nums[0] - 1) * 81 * (digit - 1) * (digit - 2) / 2;
    int nonZero = 0;
    for (int i = 1; i < digit; ++i) {
      if (nums[i] != 0) {
        nonZero = i;
        break;
      }
    }
    if (nonZero > 0) {
      ans += nums[nonZero] * 9 * (digit - 1 - nonZero);
      if (digit - 1 - nonZero >= 2) {
        ans += 81 * (digit - 1 - nonZero) * (digit - 2 - nonZero) / 2;
      }
    }
    if (digit > 3) {
      ans += 729 * (digit - 1) * (digit - 2) * (digit - 3) / 6;
    }
  }
  cout << ans << endl;
}
