#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e6 + 10;
long long a[N];
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  if (k == 1) {
    long long n = s.size();
    long long dig = s[0] - '0';
    cout << (n - 1) * 9 + dig;
  } else if (k == 2) {
    long long n = s.size();
    long long dig = s[0] - '0', ans = 0;
    for (long long i = 2; i < n; i++) ans += 81 * (i - 1);
    ans += (dig - 1) * (n - 1) * 9;
    int i = 1;
    while (i < n && s[i] == '0') i++;
    if (i == n) {
      cout << ans;
    } else {
      cout << ans + s[i] - '0' + (n - i - 1) * 9;
    }
  } else {
    long long n = s.size();
    long long dig = s[0] - '0', ans = 0;
    for (long long i = 3; i < n; i++) {
      ans += 729 * (i - 2) * (i - 1) / 2;
    }
    ans += (dig - 1) * (n - 1) * (n - 2) / 2 * 81;
    int i = 1;
    while (i < n && s[i] == '0') i++;
    if (i >= n - 1) {
      cout << ans;
    } else {
      ans += (s[i] - '0') * (n - i - 1) * 9;
      if (n - i - 1 >= 2) {
        ans += 81 * (n - i - 1 - 1) * (n - i - 1) / 2;
      }
      cout << ans;
    }
  }
  return 0;
}
