#include <bits/stdc++.h>
using namespace std;
const long long M = 105;
long long dp[M][M][5];
long long K;
long long countInRangeUtil(long long pos, long long cnt, long long tight,
                           vector<long long> 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 ans = 0;
  long long limit = (tight ? 9 : num[pos]);
  for (long long dig = 0; dig <= limit; dig++) {
    long long currCnt = cnt;
    if (dig != 0) currCnt++;
    long long currTight = tight;
    if (dig < num[pos]) currTight = 1;
    ans += countInRangeUtil(pos + 1, currCnt, currTight, num);
  }
  return dp[pos][cnt][tight] = ans;
}
long long countInRange(string s) {
  vector<long long> num;
  while (s.size()) {
    num.push_back(s.back() - '0');
    s.pop_back();
  }
  reverse(num.begin(), num.end());
  memset(dp, -1, sizeof(dp));
  return countInRangeUtil(0, 0, 0, num);
}
int main() {
  string s;
  cin >> s;
  cin >> K;
  long long x = countInRange(s);
  long long z = K;
  if (K == 3) {
    K = 2;
    x -= countInRange(s);
  } else if (K == 2) {
    K = 1;
    x -= countInRange(s);
  }
  if (K == 1) {
    x--;
  }
  cout << x << endl;
  return 0;
}
