#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    exit(0);
  }
}
const int MOD = 1000000007;
const int INF = 1 << 30;
const int n1 = 9, n2 = 81, n3 = 729;
int main() {
  string N;
  int K;
  cin >> N >> K;
  int n = N.size();
  lint res = 0;
  for (int i = 1; i <= n - 1; i++) {
    auto t = i - 1;
    if (K == 1) {
      if (i == 1)
        res += i * n1;
      else
        res += 9;
    } else if (K == 2) {
      if (i < 2)
        continue;
      else
        res += n2 * t;
    } else {
      if (i < 3)
        continue;
      else
        res += n3 * t * (t - 1) / 2;
    }
  }
  if (K == 1) {
    res += N[0] - '0';
  } else if (K == 2) {
    int t1 = N[0] - '0';
    res += (t1 - 1) * (n - 1) * 9;
    res += 9 * (n - 2);
    int t2 = N[1] - '0';
    res += t2;
  } else {
    int t1 = N[0] - '0';
    lint ts = 0;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        ts += 81;
      }
    }
    res += (t1 - 1) * ts;
    for (int i = 1; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (i == 1) {
          int t2 = N[1] - '0';
          res += t2 * 9;
        } else {
          res += 81;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
