#include <bits/stdc++.h>
using namespace std;
using gra = vector<vector<long long>>;
using gram = vector<unordered_map<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;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T dup(T a, T b) {
  return (a + b - 1) / b;
}
template <class T>
T modpow(T x, T p, T m) {
  T a = 1;
  while (p) {
    if (p % 2) a = a * x % m;
    x = x + x % m;
    p /= 2;
  }
  return a;
}
template <typename T>
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while (n > 0) {
    if (n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string n;
  long long k;
  cin >> n >> k;
  long long dp[n.length() + 1][4];
  dp[0][0] = 1;
  for (long long i = 1; i <= 3; ++i) {
    dp[0][i] = 0;
  }
  for (long long i = 1; i <= n.length() - 1; ++i) {
    dp[i][0] = 1;
    for (long long j = 1; j <= 3; ++j) {
      dp[i][j] = dp[i - 1][j - 1] * 9;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n.length(); ++i) {
    long long keta = n.length() - i;
    ans += dp[keta - 1][k - 1] * (n[i] - '0');
    ans += dp[keta - 1][k];
  }
  cout << (ans) << "\n";
  return 0;
}
