#include <bits/stdc++.h>
using namespace std;
long long dp3(long long n) { return 121.5 * (n) * (n - 1) * (n - 2); }
long long dp2(long long n) { return 40.5 * (n) * (n - 1); }
long long dp1(long long n) { return 9 * n; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    string s;
    long long k;
    cin >> s >> k;
    long long n = s.size(), k1, k2, k3, c = 0;
    for (long long i = 0; i < n; ++i) {
      if (s[i] != '0') {
        c++;
        if (c == 1) {
          k1 = i;
        } else if (c == 2) {
          k2 = i;
        } else if (c == 3) {
          k3 = i;
        }
      }
    }
    if (k == 3) {
      long long n1 = n - k1, n2 = n - k2, n3 = n - k3;
      cout << dp3(n1 - 1) + (dp2(n1 - 1) * ((s[k1] - '0') - 1)) + dp2(n2 - 1) +
                  (dp1(n2 - 1) * ((s[k2] - '0') - 1)) +
                  ((s[k3] - '0') * n3 + (9 - (s[k3] - '0')) * (n3 - 1));
    } else if (k == 2) {
      long long n1 = n - k1, n2 = n - k2;
      cout << dp2(n1 - 1) + dp1(n1 - 1) * ((s[k1] - '0') - 1) +
                  (s[k2] - '0') * n2 + (9 - (s[k2] - '0')) * (n2 - 1);
    } else {
      long long n1 = n - k1;
      cout << (s[k1] - '0') * n1 + (9 - (s[k1] - '0')) * (n1 - 1);
    }
  }
  return 0;
}
