#include <bits/stdc++.h>
using namespace std;
class solution {
 public:
  long long comb(long long n, long long k) {
    long long ans = 1;
    for (long long i = n - k + 1; i <= n; i++) {
      ans = ans * i;
    }
    long long div = 1;
    for (long long i = 1; i <= k; i++) {
      div *= i;
    }
    return ans / div;
  }
  void solve() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    int len = s.size() - 1;
    long long n = len + 1;
    long long ans = 0;
    if (len >= k) {
      ans = comb(len, k) * pow(9, k);
    }
    if (k == 1) {
      ans += s[0] - 48;
    } else if (k == 2 && n >= k) {
      long long val1 = s[0] - 48;
      long long val2 = s[1] - 48;
      ans += val2;
      ans += (val1 - 1) * len * 9;
      if (n > 2) {
        ans += 1 * (len - 1) * 1 * 9;
      }
    } else if (k == 3 && n >= k) {
      long long val1 = s[0] - 48;
      long long val2 = s[1] - 48;
      long long val3 = s[2] - 48;
      ans += val3;
      ans += (val2 - 1) * (len - 1) * 9;
      ans += (val1 - 1) * comb(len, 2) * pow(9, 2);
    }
    cout << ans;
  }
};
int main() {
  ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  long long i = 0;
  solution s;
  s.solve();
  return 0;
}
