#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K, l, a, b, c;
  cin >> N >> K;
  l = N.size();
  a = N.at(0) - '0';
  if (l == 1) {
    if (K == 1) {
      cout << a << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  } else {
    b = N.at(1) - '0';
    if (l == 2) {
      if (K == 1) {
        cout << a + 9 << endl;
        return 0;
      } else if (K == 2) {
        if (b == 0) {
          cout << 0 << endl;
          return 0;
        } else {
          cout << (a - 1) * 9 + b << endl;
          return 0;
        }
      } else {
        cout << 0 << endl;
        return 0;
      }
    } else {
      c = N.at(2) - '0';
      if (K == 1) {
        cout << a + 9 * (l - 1) << endl;
        return 0;
      } else if (K == 2) {
        int64_t ans = 0;
        ans += (a - 1) * 9 + b;
        if (b == 0)
          ans += a * c;
        else
          ans += a * 9;
        ans += a * 9 * (l - 3);
        ans += 9 * 9 * (((l - 1) * (l - 2)) / 2);
        cout << ans << endl;
        return 0;
      } else {
        int64_t ans = 0;
        ans += (a - 1) * 9 * 9 + (b - 1) * 9 + c;
        ans += ((a - 1) * 9 + b) * 9 * (l - 3);
        if (b == 0)
          ans += ((a - 1) * 9 + c) * 9 * (l - 3);
        else
          ans += a * 9 * 9 * (l - 3);
        if (b == 0 && c == 0) {
          if (l >= 5) {
            int d = N.at(3) - '0';
            ans += ((a - 1) * 9 + d) * 9 * (l - 4);
          }
        } else
          ans += a * 9 * 9 * (((l - 3) * (l - 4)) / 2);
        ans += 9 * 9 * 9 * (((l - 1) * (l - 2) * (l - 3)) / 6);
        cout << ans << endl;
        return 0;
      }
    }
  }
}
