#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  long long K;
  cin >> N >> K;
  long long SN = N.size();
  long long n[SN];
  for (int i = (0); i < (SN); ++i) n[i] = N[i] - '0';
  long long dp[101][4];
  for (int i = (0); i < (4); ++i) dp[0][i] = 0;
  for (int i = (0); i < (101); ++i) dp[i][0] = 1;
  for (int i = (1); i < (101); ++i)
    for (int j = (1); j < (4); ++j) {
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] * 9;
    }
  long long ans = 0;
  ans += dp[SN - 1][K];
  if (K >= 1) {
    ans += dp[max((long long)0, SN - 2)][K - 1];
    ans += (n[0] - 1) * dp[SN - 1][K - 1];
  }
  if (K >= 2) {
    int c = 0;
    for (int i = (0); i < (SN); ++i) {
      if (n[i] != 0) c++;
      if (c == 2) {
        ans += dp[SN - i - 2][K - 2];
      }
    }
    for (int i = (1); i < (SN - 1); ++i) {
      if (n[i] != 0) {
        ans += (n[i] - 1) * dp[SN - 1 - i][K - 2];
        break;
      }
    }
  }
  if (K >= 3) {
    int c = 0;
    for (int i = (0); i < (SN); ++i) {
      if (n[i] != 0) c++;
      if (c == 3) {
        ans += dp[SN - i - 2][K - 3];
      }
    }
    for (int i = (2); i < (SN - 1); ++i) {
      if (n[i] != 0) {
        ans += (n[i] - 1) * dp[SN - 1 - i][K - 3];
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
