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