#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long dp[510][5][2];
int main() {
  string s;
  cin >> s;
  long long K;
  cin >> K;
  long long N = s.size();
  dp[0][0][1] = 1;
  for (long long i = 0; i < N; i++) {
    long long d = s[i] - '0';
    for (long long j = 0; j < K + 1; j++) {
      dp[i + 1][j + 1][0] += dp[i][j][0] * 9 + dp[i][j][1] * (d - 1);
      dp[i + 1][j + 1][1] += dp[i][j][1];
      dp[i + 1][j][0] += dp[i][j][0] + dp[i][j][1];
    }
  }
  cout << dp[N][K][0] + dp[N][K][1] << endl;
}
