#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  long long k, ans = 0;
  cin >> s >> k;
  deque<long long> v;
  for (long long i = 0; i < s.size(); i++) v.emplace_front(s[i] - '0');
  if (k == 1) {
    for (long long i = 0; i < v.size() - 1; i++) {
      ans += 9;
    }
    ans += v[v.size() - 1];
  } else if (k == 2) {
    for (long long i = 1; i < v.size(); i++) {
      long long t = 9;
      bool b1 = (i == v.size() - 1);
      if (b1) t = v[i];
      bool allz = true;
      for (long long j = i - 1; j >= 0; j--) {
        allz = allz && (v[j] == 0);
        bool b2 = (j == i - 1);
        long long t2 = (t - 1) * 9;
        if (b1 && (b2 || allz)) {
          t2 += v[j];
        } else {
          t2 += 9;
        }
        ans += t2;
      }
    }
  } else {
    for (long long i = 2; i < v.size(); i++) {
      long long t1 = 9;
      bool b1 = (i == v.size() - 1);
      if (b1) t1 = v[i];
      bool allz1 = true;
      for (long long j = 1; j < i; j++) {
        allz1 = allz1 && (v[j] == 0);
        long long t2 = (t1 - 1) * 9;
        bool b2 = (j == i - 1);
        if (b1 && (b2 || allz1)) {
          t2 += v[j];
        } else {
          t2 += 9;
        }
        if (t2 == 0) continue;
        bool allz2 = true;
        for (long long k = 0; k < j; k++) {
          allz2 = allz2 && (v[k] == 0);
          long long t3 = (t2 - 1) * 9;
          if (b1 && ((b2 && k == j - 1) || (b2 && allz2) || (allz1 && allz2))) {
            t3 += v[k];
          } else {
            t3 += 9;
          }
          ans += t3;
        }
      }
    }
  }
  printf("%lld\n", ans);
}
