#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int m = s.size();
  vector<int> n(m);
  for (int i = 0; i < m; i++) n[i] = s[i] - '0';
  long long int ans = 0;
  if (m <= 3) {
    int p = stoi(s);
    for (int i = 1; i <= p; i++) {
      int nonzero = 0;
      int x = i;
      while (x > 0) {
        if (x % 10 != 0) nonzero++;
        x /= 10;
      }
      if (nonzero == k) ans++;
    }
  } else {
    if (k == 1) {
      for (int h = 0; h < m; h++) {
        long long int addition = 9;
        if (h == 0) {
          addition -= 9 * (9 - n[0]);
        }
        ans += addition;
      }
    } else if (k == 2) {
      for (int h = 0; h < m; h++) {
        bool lim2 = true;
        for (int i = h + 1; i < m; i++) {
          long long int addition = 81;
          if (h == 0) {
            addition -= 9 * (9 - n[0]);
            if (lim2) {
              addition -= (9 - n[1]);
              if (n[i] > 0) lim2 = false;
            }
          }
          ans += addition;
        }
      }
    } else if (k == 3) {
      for (int h = 0; h < m; h++) {
        bool lim2 = true;
        for (int i = h + 1; i < m; i++) {
          bool lim3 = true;
          for (int j = i + 1; j < m; j++) {
            long long int addition = 729;
            if (h == 0) {
              addition -= 81 * (9 - n[0]);
              if (lim2) {
                addition -= 9 * (9 - n[1]);
                if (n[i] > 0) lim2 = false;
                if (lim3) {
                  addition -= (9 - n[1]);
                  if (n[j] > 0) lim3 = false;
                }
              }
            }
            ans += addition;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
