#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  string N;
  int K;
  cin >> N >> K;
  int L = N.length();
  if (L < K) {
    cout << 0 << endl;
    return 0;
  }
  long long count = 0;
  for (int i = (1); i < (L); ++i) {
    if (i >= K) {
      if (K == 1) {
        count += 9;
      } else if (K == 2) {
        count += 9 * 9 * (i - 1);
      } else {
        count += 9 * 81 * (i - 1) * (i - 2) / 2;
      }
    }
  }
  int p = (int)(N[0] - '0');
  long long lp = 0;
  if (K == 1)
    lp = p - 1;
  else if (K == 2)
    lp = (p - 1) * 9 * (L - 1);
  else
    lp = (p - 1) * 81 * (L - 1) * (L - 2) / 2;
  if (K == 1)
    lp += 1;
  else if (K == 2) {
    long long c = 0;
    bool f = false;
    for (int i = (1); i < (L); ++i) {
      if (f) {
        c += 9;
      } else {
        int a = (int)(N[i] - '0');
        if (a > 0) {
          f = true;
          c += a;
        }
      }
    }
    lp += c;
  } else {
    int q = (int)(N[1] - '0');
    long long lq = 0;
    lq += 81 * (L - 2) * (L - 3) / 2;
    lq += (q - 1) * 9 * (L - 2);
    long long c = 0;
    bool f = false;
    for (int i = (2); i < (L); ++i) {
      if (f) {
        c += 9;
      } else {
        int a = (int)(N[i] - '0');
        if (a > 0) {
          f = true;
          c += a;
        }
      }
    }
    lq += c;
    lp += lq;
  }
  cout << count + lp << endl;
  return 0;
}
