#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = int(2e9);
const long long LINF = long long(2e9) * long long(2e9);
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  vector<vector<vector<long long>>> dp(
      N + 1, vector<vector<long long>>(10, vector<long long>(3 + 1)));
  vector<vector<vector<long long>>> dp2(
      N + 1, vector<vector<long long>>(10, vector<long long>(3 + 1)));
  dp[0][0][0] = 1;
  reverse(S.begin(), S.end());
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 4; k++) {
        if (j != 0) {
          if (k == 0) continue;
          for (int l = 0; l < 10; l++) {
            dp[i][j][k] += dp[i - 1][l][k - 1];
          }
        } else {
          for (int l = 0; l < 10; l++) {
            dp[i][j][k] += dp[i - 1][l][k];
          }
        }
      }
    }
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 4; k++) {
        if (j < S[i - 1] - 0x30) {
          if (j != 0) {
            if (k == 0) continue;
            for (int l = 0; l < 10; l++) {
              dp2[i][j][k] += dp[i - 1][l][k - 1];
            }
          } else {
            for (int l = 0; l < 10; l++) {
              dp2[i][j][k] += dp[i - 1][l][k];
            }
          }
        } else if (j == S[i - 1] - 0x30) {
          if (j != 0) {
            if (k == 0) continue;
            for (int l = 0; l < 10; l++) {
              dp2[i][j][k] += dp2[i - 1][l][k - 1];
            }
          } else {
            for (int l = 0; l < 10; l++) {
              dp2[i][j][k] += dp2[i - 1][l][k];
            }
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 10; i++) ans += dp2[N][i][K];
  if (S[N - 1] < S[N - 2]) ans++;
  cout << ans << endl;
  return 0;
}
