#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  long long ans = 0;
  cin >> s >> k;
  int ssize = s.size();
  if (k == 1) {
    if (ssize == 1) {
      cout << s << '\n';
      return 0;
    } else {
      ans = (ssize - 1) * 9;
      for (int i = 0; i < ssize; ++i) {
        ans += s[i] - '0';
      }
    }
  } else if (k == 2) {
    if (ssize == 1) {
      cout << 0 << '\n';
      return 0;
    } else if (ssize == 2) {
      ans = (s[0] - '0' - 1) * 9 + s[1] - '0';
    } else {
      ans = 81 * (ssize - 2) * (ssize - 1) / 2 +
            (s[0] - '0' - 1) * 9 * (ssize - 1);
      int l = ssize + 1;
      for (int i = 1; i < ssize; ++i) {
        if (s[i] != '0') {
          l = i;
          break;
        }
      }
      ans += 9 * (ssize - l - 1);
      if (l != ssize + 1) ans += s[l] - '0';
    }
  } else {
    if (ssize < 3) {
      cout << 0 << '\n';
      return 0;
    } else if (ssize == 3) {
      ans = (s[0] - '0') * 81 + s[1] * s[2];
    } else {
    }
  }
  cout << ans << '\n';
  return 0;
}
