#include <bits/stdc++.h>
using namespace std;
using _loop_ll = long long;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
constexpr long long int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string S;
  int K;
  cin >> S;
  cin >> K;
  int N = S.size();
  vi A;
  for (char ch : S) {
    A.push_back(ch - '0');
  }
  ll ans = 0;
  if (K == 1) {
    for (int i = 0; i < N; i++) {
      if (i == 0) {
        ans += A[0];
      } else {
        ans += 9;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (K == 2) {
    for (int i = 0; i < N - 1; i++) {
      if (i == 0) {
        for (int j = 1; j < N; j++) {
          if (j == 1) {
            ans += (A[0] - 1) * 9 + A[1];
          } else {
            ans += A[0] * 9;
          }
        }
      } else {
        ans += (N - i - 1) * 81;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (K == 3) {
    for (int i = 0; i < N - 2; i++) {
      if (i == 0) {
        for (int j = 1; j < N - 1; j++) {
          if (j == 1) {
            for (int k = 2; k < N; k++) {
              if (k == 2) {
                if (A[1] == 0) {
                  ans += (A[0] - 1) * 81;
                } else {
                  ans += (A[0] - 1) * 81 + (A[1] - 1) * 9 + A[2];
                }
              } else {
                ans += (A[0] - 1) * 81 + A[1] * 9;
              }
            }
          } else {
            ans += A[0] * (N - j - 1) * 81;
          }
        }
      } else {
        ans += (N - i - 1) * (N - i - 2) / 2 * 729;
      }
    }
    cout << ans << endl;
    return 0;
  }
  return 0;
};
