#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;
int main() {
  string IN;
  int K;
  cin >> IN >> K;
  vector<int> N;
  for (char &c : IN) N.push_back(c - '0');
  int n = N.size();
  long long ans = 0;
  if (K == 1) {
    for (int i = 0; i < (n); ++i) {
      if (i == 0)
        ans += N[0];
      else
        ans += 9;
    }
  } else if (K == 2) {
    for (int i = 0; i < (n); ++i)
      for (int j = 0; j < (n); ++j) {
        if (j <= i) continue;
        if (i == 0) {
          if (j == 1) {
            ans += (N[0] - 1) * 9;
            ans += N[1];
          } else {
            ans += N[0] * 9;
          }
        } else {
          ans += 9 * 9;
        }
      }
  } else {
    for (int i = 0; i < (n); ++i)
      for (int j = 0; j < (n); ++j)
        for (int k = 0; k < (n); ++k) {
          if (j <= i || k <= i || k <= j) continue;
          if (i == 0) {
            if (j == 1) {
              if (k == 2) {
                ans += (N[0] - 1) * 9 * 9;
                ans += (N[1] - 1) * 9;
                ans += N[2];
              } else {
                ans += N[0] * N[1] * 9;
              }
            } else {
              ans += N[0] * 9 * 9;
            }
          } else {
            ans += 9 * 9 * 9;
          }
        }
  }
  cout << ans << endl;
}
