#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001000;
const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
long long big = 0, small = 0;
long long lt = 0, mid = 0;
void dfs(string now, string to, int m_len) {
  if (now.size() == m_len) {
    if (now <= to) {
      ++small;
    } else {
      if (now.substr(0, now.size() - 1) == to.substr(0, to.size() - 1)) {
        ++lt;
      } else {
        if (to.size() == 3) {
          if (now[0] == to[0]) {
            mid++;
            return;
          }
        }
        ++big;
      }
    }
  } else {
    for (int i = 1; i <= 9; ++i) {
      string n = now + (char)('0' + i);
      dfs(n, to, m_len);
    }
  }
}
long long comb_modM(long long n, long long r, long long M = MOD) {
  if (n == 0) return 0;
  if (r < 0) return 0;
  long long ans = 1;
  for (int i = 0; i < r; ++i) {
    ans *= (n - i);
  }
  long long divisor = 1;
  for (int i = 0; i < r; ++i) {
    divisor *= (i + 1);
  }
  ans /= divisor;
  return ans;
}
int main() {
  string s;
  int K;
  cin >> s >> K;
  int N = s.size();
  string t;
  if (N >= K) {
    t = s.substr(0, K);
  } else {
    t = s;
  }
  dfs("", t, K);
  long long ans = 0;
  {
    if (N - K >= 1) {
      long long kake = comb_modM(N, K);
      ans += kake * small;
      ans += (kake - 1) * lt;
      ans += (kake - K - 1) * mid;
    } else if (N - K == 0) {
      ans += small;
    }
  }
  {
    if (N - K - 1 >= 1) {
      ans += comb_modM(N - 1, K) * big;
    } else if (N - K - 1 == 0) {
      ans += big;
    }
  }
  cout << ans << endl;
  return 0;
}
