#include <bits/stdc++.h>
using namespace std;
const long long int M = 200;
long long int dp[M][M][2];
int K;
long long int countInRangeUtil(long long int pos, long long int cnt,
                               long long int tight, vector<long long int> num) {
  if (pos == num.size()) {
    if (cnt == K) return 1;
    return 0;
  }
  if (dp[pos][cnt][tight] != -1) return dp[pos][cnt][tight];
  long long int ans = 0;
  long long int limit = (tight ? 9 : num[pos]);
  for (int dig = 0; dig <= limit; dig++) {
    long long int currCnt = cnt;
    if (dig != 0) currCnt++;
    long long int currTight = tight;
    if (dig < num[pos]) currTight = 1;
    ans += countInRangeUtil(pos + 1, currCnt, currTight, num);
  }
  return dp[pos][cnt][tight] = ans;
}
long long int countInRange(long long int x) {
  vector<long long int> num;
  while (x) {
    num.push_back(x % 10);
    x /= 10;
  }
  reverse(num.begin(), num.end());
  memset(dp, -1, sizeof(dp));
  return countInRangeUtil(0, 0, 0, num);
}
int main() {
  long long int n;
  cin >> n;
  int k;
  cin >> k;
  K = k;
  cout << countInRange(n);
  return 0;
}
