#include <bits/stdc++.h>
using ll = long long;
using namespace std;
long long x = 1000000007;
ll n_pow(ll a, ll n) {
  if (n == 0) return 1;
  ll t = n_pow(a, n / 2);
  t *= t;
  t %= x;
  if (n % 2 == 1) t *= a;
  return t % x;
}
const int INF = 1001001001;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  ll ans;
  if (k == 1) {
    ans = (n - 1) * 9;
    int x = s[0] - '0';
    ans += x;
  } else if (k == 2) {
    ans = 81 * (n - 1) * (n - 2) / 2;
    int x = s[0] - '0';
    ans += (x - 1) * (n - 1) * 9;
    for (int i = 1; i < n; i++) {
      int y = s[i] - '0';
      ans += y;
    }
  } else {
    ans = 729 * (n - 1) * (n - 2) * (n - 3) / 6;
    int x = s[0] - '0';
    ans += (x - 1) * 81 * (n - 1) * (n - 2) / 2;
    for (int i = 1; i < n; i++) {
      int y = s[i] - '0';
      for (int j = i + 1; j < n; j++) {
        int z = s[j] - '0';
        ans += y * z;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
