#include <bits/stdc++.h>
using namespace std;
long long dp[101][2][4];
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long N, K;
  cin >> N >> K;
  string s = to_string(N);
  long long len = s.length();
  dp[0][0][0] = 1;
  for (long long d = 0; d < len; d++) {
    for (long long smaller = 0; smaller < 2; smaller++) {
      for (long long k = 0; k <= K; k++) {
        for (long long x = 0; x <= (smaller ? 9 : (s[d] - '0')); x++) {
          dp[d + 1][smaller || x < (s[d] - '0')][(x != 0 ? k + 1 : k)] +=
              dp[d][smaller][k];
        }
      }
    }
  }
  cout << dp[len][0][3] + dp[len][1][3] << endl;
  return 0;
}
