#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const long long MOD = 1e9 + 7;
long long comb(int m, int n) {
  long long up = 1, down = 1;
  for (int i = (m - n + 1); i <= (m); i++) up *= i;
  for (int i = (1); i <= (n); i++) down *= i;
  return up / down;
}
int main() {
  string n;
  int k;
  long long ans;
  while (cin >> n >> k) {
    int len = n.size();
    ans = pow(9, k) * comb(len - 1, k);
    if (k == 1)
      ans += n[0] - '0';
    else if (k == 2) {
      ans += (n[0] - '1') * comb(len - 1, 1) * 9;
      int x = 1;
      while (x < len && n[x++] == '0')
        ;
      ans += comb(len - x, 1) * 9;
      ans += n[x - 1] - '0';
    } else {
      ans += (n[0] - '1') * comb(len - 1, 2) * 9 * 9;
      for (int i = (1); i <= (len - 2); i++) {
        if (n[i] != '0') {
          ans += (n[i] - '1') * comb(len - i - 1, 1) * 9;
          int x = i + 1;
          while (x < len && n[x++] == '0')
            ;
          ans += comb(len - x, 1) * 9;
          ans += n[x - 1] - '0';
          if (x == len && i < len - 2) ans += comb(len - i - 1, 1) * 9;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
