#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MX = 1000001;
string N;
long long K, ans;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  vector<int> a((int)N.size());
  for (int i = (0); i < ((int)N.size()); ++i) a[i] = N[i] - '0';
  if (K == 1) {
    for (int i = (0); i < ((int)N.size()); ++i) {
      if (i == 0)
        ans += a[i];
      else
        ans += 9;
    }
  } else if (K == 2) {
    for (int i = ((int)a.size() - 1) - 1; i >= (0); --i) {
      if (i != 0) {
        ans += ((int)a.size() - (i + 1)) * 9 * 9;
      } else {
        bool secondDigit = false;
        for (int j = (1); j < ((int)a.size()); ++j) {
          if (secondDigit)
            ans += a[i] * 9;
          else {
            if (a[j]) {
              secondDigit = true;
              ans += a[j];
              ans += (a[i] - 1) * 9;
            }
          }
        }
      }
    }
  } else {
    for (int i = ((int)a.size() - 2) - 1; i >= (0); --i) {
      if (i != 0) {
        long long toRight = (int)a.size() - (i + 1);
        long long combos = toRight * (toRight - 1) / 2;
        ans += combos * 729;
      } else {
        bool second = false, third = false;
        for (int j = (1); j < ((int)a.size() - 1); ++j) {
          if (!a[j] && !second) continue;
          for (int k = (j + 1); k < ((int)a.size()); ++k) {
            if (!second) {
              if (third)
                ans += a[i] * a[j] * 9;
              else {
                if (!a[k]) continue;
                ans += a[i] * a[j] * a[k];
                third = true;
              }
            } else {
              ans += a[i] * 9 * 9;
            }
          }
          second = true;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
