#include <bits/stdc++.h>
using namespace std;
long long INF = LLONG_MAX;
long long dp[102][2][3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int K;
  cin >> s >> K;
  for (int i = 0; i < 102; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 3; k++) dp[i][j][k] = 0;
  int n = s.length();
  dp[0][0][0] = 1;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int cur = s[i] - '0';
    for (int j = 0; j <= K; j++) {
      for (int k = 0; k < 2; k++) {
        if (dp[i][j][k] == 0) continue;
        for (int num = 0; num <= 9; num++) {
          if (k == 0 && num > cur) continue;
          if (j + (num > 0 ? 1 : 0) > K) continue;
          dp[i + 1][int(j + (num > 0 ? 1 : 0))][int(k | (num < cur ? 1 : 0))] +=
              dp[i][j][k];
        }
      }
    }
  }
  sum += dp[n][K][0] + dp[n][K][1];
  cout << sum << endl;
}
