#include <bits/stdc++.h>
using namespace std;
long long dp[100][100][2];
long long digitDp(long long pos, long long nonzero, bool islimit, string num,
                  long long k) {
  if (pos > (int)num.size()) {
    return nonzero == k;
  }
  if (dp[pos][nonzero][islimit] != -1) return dp[pos][nonzero][islimit];
  long long res = 0, limit = 9;
  if (islimit) limit = (num[pos - 1] - '0');
  for (long long i = 0; i <= limit; i++) {
    if (i == limit && islimit) {
      if (i > 0)
        res += digitDp(pos + 1, nonzero + 1, true, num, k);
      else
        res += digitDp(pos + 1, nonzero, true, num, k);
    } else {
      if (i > 0)
        res += digitDp(pos + 1, nonzero + 1, false, num, k);
      else
        res += digitDp(pos + 1, nonzero, false, num, k);
    }
  }
  return dp[pos][nonzero][islimit] = res;
}
int main(void) {
  for (long long i = 0; i < 100; i++)
    for (long long j = 0; j < 100; j++)
      for (long long k = 0; k < 2; k++) dp[i][j][k] = -1;
  long long k;
  string num;
  cin >> num;
  cin >> k;
  cout << digitDp(1, 0, true, num, k);
}
