#include <bits/stdc++.h>
int main() {
  char n[105];
  int k;
  scanf("%s %d", n, &k);
  int len = strlen(n);
  long dp[len][3];
  dp[len - 1][0] = (n[0] - '0');
  dp[len - 1][1] = 0;
  dp[len - 1][2] = 0;
  for (int i = 1; i < len; i++) {
    dp[len - i - 1][0] = dp[len - i][0] + 9;
    if (dp[len - i][1] == 0)
      dp[len - i - 1][1] = (dp[len - i][0] - 1) * 9 + (n[i] - '0');
    else
      dp[len - i - 1][1] = dp[len - i][1] + dp[len - i][0] * 9;
    if (dp[len - i][1] == 0)
      dp[len - i - 1][2] = 0;
    else if (dp[len - i][2] == 0) {
      dp[len - i - 1][2] = (dp[len - i][1] - 1) * 9 + (n[i] - '0');
    } else
      dp[len - i - 1][2] = dp[len - i][2] + dp[len - i][1] * 9;
  }
  printf("%ld\n", dp[0][k - 1]);
  return 0;
}
