#include <bits/stdc++.h>
using namespace std;
static const long long llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const long long llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const long long d_5 = 100000;
static const long long d9_7 = 1000000007;
static const long long d_9 = 1000000000;
static const double PI = 3.14159265358979323846;
template <class T>
void Printvector(std::vector<T> a) {
  int size = a.size();
  for (long long i = 0; i < size; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T>
void Printvector(std::vector<std::vector<T>> a) {
  int size = a.size();
  for (long long i = 0; i < size; i++) {
    int size2 = a[i].size();
    for (long long j = 0; j < size2; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
long long digitpower(long long a, long long b) {
  if (b == 1) {
    return a;
  } else if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    long long tmp = digitpower(a, (b - 1) / 2);
    tmp %= d9_7;
    tmp *= tmp;
    tmp %= d9_7;
    tmp *= a;
    return (tmp) % d9_7;
  } else {
    long long tmp = digitpower(a, (b) / 2);
    tmp %= d9_7;
    tmp *= tmp;
    tmp %= d9_7;
    return (tmp) % d9_7;
  }
}
unordered_map<long long, long long> prime_factor(int64_t n) {
  unordered_map<long long, long long> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
template <class T>
vector<T> getaccum(vector<T> a) {
  int size = a.size();
  vector<T> ans(size);
  ans[0] = a[0];
  for (int i = 0; i < size - 1; i++) {
    ans[i + 1] = ans[i] + a[i + 1];
    ans[i + 1] %= d9_7;
  }
  return ans;
}
int main(void) {
  int k;
  string n;
  cin >> n >> k;
  int size = n.size();
  vector<long long> nums1(size, 0);
  int tmp2 = 0;
  for (long long i = 0; i < size; i++) {
    if (i == 0) {
      nums1[i] = n[i] - '0' + (size - 1 - i) * 9;
    } else {
      nums1[i] = nums1[i - 1];
    }
  }
  vector<long long> nums2(size, 0);
  int pastdigits = 0;
  for (long long i = 0; i < size; i++) {
    long long tmp1 = (size - 1 - i) * 9;
    long long tmp2 = (((size - 1 - i) * (size - 1 - i - 1)) / 2) * 9 * 9;
    if (i == 0) {
      nums2[i] = tmp1 * ((n[i] - '0' - 1)) + tmp2;
      if (n[i] - '0' >= 1) {
        pastdigits++;
      }
      continue;
    }
    if (pastdigits == 0) {
      nums2[i] = nums2[i - 1] + (n[i] - '0') * tmp2;
    } else if (pastdigits == 1) {
      if (n[i] == '0') {
        nums2[i] = nums2[i - 1];
      } else {
        nums2[i] = tmp1 + (n[i] - '0' - 1) + nums2[i - 1];
      }
    } else {
      nums2[i] = nums2[i - 1];
    }
    if (n[i] - '0' >= 1) {
      pastdigits++;
    }
  }
  if (n[size - 1] >= 1) nums2[size - 1]++;
  vector<long long> nums3(size, 0);
  pastdigits = 0;
  for (long long i = 0; i < size; i++) {
    long long tmp1 = (size - 1 - i) * 9;
    long long tmp2 = 9 * 9 * (((size - 1 - i) * (size - 1 - i - 1)) / 2);
    long long tmp3 =
        (((size - 1 - i) * (size - 1 - i - 1) * (size - 1 - i - 2)) / 6) * 9 *
        9 * 9;
    if (i == 0) {
      nums3[i] = tmp2 * ((n[i] - '0' - 1)) + tmp3;
      if (n[i] - '0' >= 1) {
        pastdigits++;
      }
      continue;
    }
    if (pastdigits == 0) {
      nums3[i] = nums3[i - 1] + (n[i] - '0') * tmp3;
    } else if (pastdigits == 1) {
      if (n[i] == '0') {
        nums3[i] = nums3[i - 1];
      } else {
        nums3[i] = nums3[i - 1] + (n[i] - '0' - 1) * tmp1 + tmp2;
      }
    } else if (pastdigits == 2) {
      nums3[i] = nums3[i - 1] + (n[i] - '0' - 1) + tmp1;
    } else {
      nums3[i] = nums3[i - 1];
    }
    if (n[i] - '0' >= 1) {
      pastdigits++;
    }
  }
  if (n[size - 1] >= 1) nums3[size - 1]++;
  if (k == 2) {
    cout << nums2[size - 1] << endl;
  } else if (k == 3) {
    cout << nums3[size - 1] << endl;
  } else if (k == 1) {
    cout << nums1[size - 1] << endl;
  }
  return 0;
}
