#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<vvi> dp(100, vvi(10, vi(4)));
  dp[0][0][0] = 1;
  for (int i = 0; i < 9; i++) dp[0][i + 1][1] = 1;
  for (int i = 1; i < 100; i++) {
    for (int k = 0; k < 10; k++) {
      for (int l = 0; l < 4; l++) {
        dp[i][0][l] += dp[i - 1][k][l];
      }
    }
    for (int j = 1; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        for (int l = 1; l < 4; l++) {
          dp[i][j][l] += dp[i - 1][k][l - 1];
        }
      }
    }
  }
  string s;
  int k0;
  cin >> s >> k0;
  function<int(int, int, bool)> count = [&](int i, int k, bool lim) {
    if (k == 0) return 0;
    int ret = 0;
    for (int j = !!i; j < (lim ? s[(int)s.size() - i - 1] - '0' : 10); j++)
      ret += dp[i][j][k];
    if (i) {
      ret += count(i - 1, k, false);
      if (lim) ret += count(i - 1, k - 1, true);
    }
    return ret;
  };
  cout << count((int)s.size() - 1, k0, true) + 1;
  return 0;
}
