#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  for (int i = 0; i < ((int)vec.size()); i++) os << (i ? ", " : "") << vec[i];
  os << "]";
  return os;
}
template <typename T>
istream& operator>>(istream& is, pair<T, T>& p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T, T>& p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
bool operator<(vector<T>& a, vector<T>& b) {
  for (int i = 0; i < ((int)a.size()); i++) {
    if (i == b.size()) return false;
    if (a[i] < b[i])
      return true;
    else if (a[i] > b[i])
      return false;
  }
  return false;
}
template <typename T>
bool operator>(vector<T>& a, vector<T>& b) {
  for (int i = 0; i < ((int)a.size()); i++) {
    if (i == b.size()) return true;
    if (a[i] < b[i])
      return false;
    else if (a[i] > b[i])
      return true;
  }
  return false;
}
int bitcnt(long long x) {
  x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
  x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
  x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
  x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
  x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
  x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
  return x;
}
int bitcnt(int x) {
  x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
  x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
  x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
  x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
  x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
  return x;
}
long long sqrtll(long long x) {
  long long left = 0, right = x;
  for (int i = 0; i < ((int)100); i++) {
    long long mid = (left + right) >> 1;
    if (mid * mid <= x)
      left = mid;
    else
      right = mid;
  }
  return left;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const long double infl = 1e100;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long inf = 1e15;
const int dx[] = {1, 0, -1, 0, 0};
const int dy[] = {0, 1, 0, -1, 0};
long long base_mod = 1420622537;
string n;
long long cnt(int i, int k) {
  if (n.size() - i < k) return 0;
  if (k == 1) {
    long long res = (n.size() - i - 1) * 9 + (n[i] - '0');
    cerr << i << " " << k << ":" << res << endl;
    return res;
  }
  if (n[i] == '0') {
    long long res = cnt(i + 1, k);
    cerr << i << " " << k << ":" << res << endl;
    return res;
  }
  long long cnt1 = (n[i] - '0' - 1);
  for (int j = 1; j < ((int)k); j++) {
    cnt1 *= (n.size() - i - j) * 9;
    cnt1 /= j;
  }
  long long cnt2 = 1;
  for (int j = 1; j <= ((int)k); j++) {
    cnt2 *= (n.size() - i - j) * 9;
    cnt2 /= j;
  }
  long long res = cnt1 + cnt(i + 1, k - 1) + cnt2;
  cerr << i << " " << k << ":" << res << endl;
  return res;
}
int main() {
  cin >> n;
  int k;
  cin >> k;
  cout << cnt(0, k) << endl;
  return 0;
}
