#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a[n];
  for (int i = 0; i < (n); ++i) a[i] = s[i] - '0';
  int k;
  cin >> k;
  int dp[n][4];
  int cnt = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (4); ++j) dp[i][j] = 0;
  for (int i = 0; i < (n); ++i) {
    if (i == 0) {
      dp[i][0] = a[i] - 1;
    } else {
      dp[i][0] = dp[i - 1][0] * 9 + 9;
      dp[i][1] = dp[i - 1][0] + dp[i - 1][1] * 9;
      dp[i][2] = dp[i - 1][1] + dp[i - 1][2] * 9;
      dp[i][3] = dp[i - 1][2] + dp[i - 1][3] * 9;
      if (a[i] == 0) {
        cnt++;
      } else {
        if (cnt <= 2) {
          dp[i][cnt + 1]++;
        }
        if (a[i] >= 2 && cnt <= 3) {
          dp[i][cnt] += a[i] - 1;
        }
      }
    }
  }
  int ans = dp[n - 1][k];
  if (cnt == k) ans++;
  cout << ans << endl;
  return 0;
}
