#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
using V = vector<T>;
using Graph = vector<vector<int>>;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1000000000000000000;
signed main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long m = s.size();
  long long ans = 0;
  if (k == 1) {
    ans += 9 * (m - 1);
    ans += s[0] - '0';
  } else if (k == 2) {
    if (m >= 2) {
      long long a = s[0] - '0', b = s[1] - '0';
      ans += (s[1] - '0');
      ans += (m - 2) * 9;
      ans += 9 * (m - 1) * (a - 1);
      ans += 81 * (m - 1) * (m - 2) / 2;
    }
  } else {
    if (m >= 3) {
      long long a = s[0] - '0', b = s[1] - '0', c = s[2] - '0';
      ans += b * c;
      ans += 9 * (m - 3) * b;
      ans += 81 * (m - 2) * (m - 3) / 2;
      ans += (a - 1) * 81 * (m - 1) * (m - 2) / 2;
      long long cnt = 0;
      for (long long i = 2; i <= m - 2; i++) cnt += i * (i - 1);
      cnt *= 9 * 9 * 9;
      cnt /= 2;
      ans += cnt;
    }
  }
  cout << ans << endl;
}
