#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
long long now() {
  return chrono::duration_cast<chrono::milliseconds>(
             chrono::system_clock::now().time_since_epoch())
      .count();
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  time_t start = now();
  string n;
  cin >> n;
  long long k;
  cin >> k;
  long long res = 0;
  long long m = n.length();
  if (k == 1) {
    res = (n[0] - '0') + (m - 1) * 9;
  } else if (k == 2) {
    if (m > 1) {
      res += (((n[0] - '0') * (m - 1) * 9) - (9 - (n[1] - '0')));
      for (long long i = 1; i < m - 1; i++) {
        for (long long j = i + 1; j < m; j++) {
          res += 81;
        }
      }
    }
  } else {
    if (m > 2) {
      for (long long i = 1; i < m - 1; i++) {
        for (long long j = i + 1; j < m; j++) {
          res += 81;
        }
      }
      res *= (n[0] - '0' - 1);
      res += (((n[1] - '0') * (m - 2) * 9) - (9 - (n[2] - '0')));
      for (long long i = 2; i < m - 1; i++) {
        for (long long j = i + 1; j < m; j++) {
          res += 81;
        }
      }
      for (long long i = 1; i < m - 2; i++) {
        for (long long j = i + 1; j < m - 1; j++) {
          for (long long k = j + 1; k < m; k++) {
            res += (9 * 9 * 9);
          }
        }
      }
    }
  }
  cout << res << "\n";
  cerr << "TIME => " << now() - start << "\n";
  return 0;
}
