#include <bits/stdc++.h>
using namespace std;
int c2i(char c) { return c - '0'; }
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int len = s.size();
  long long ans = 0;
  if (k == 1) {
    for (long long i = (long long)(0); i < (long long)(len); ++i) {
      if (i == 0) {
        ans += c2i(s[i]);
      } else {
        ans += 9;
      }
    }
  }
  if (k == 2) {
    for (long long i = (long long)(0); i < (long long)(len); ++i) {
      bool flag = false;
      for (long long j = (long long)(i + 1); j < (long long)(len); ++j) {
        if (i == 0) {
          if (flag)
            ans += 1 * 9;
          else
            ans += 1 * c2i(s[j]);
          ans += c2i(s[i] - 1) * 9;
        } else {
          ans += 81;
        }
        flag |= s[j] != '0';
      }
    }
  }
  if (k == 3) {
    for (long long i = (long long)(0); i < (long long)(len); ++i) {
      bool flag1 = false;
      for (long long j = (long long)(i + 1); j < (long long)(len); ++j) {
        bool flag2 = false;
        for (long long k = (long long)(j + 1); k < (long long)(len); ++k) {
          if (i == 0) {
            if (flag1) {
              ans += 1 * 81;
            } else if (!flag1 && flag2) {
              ans += 1 * (c2i(s[j]) - 1) * 9;
              ans += 1 * 1 * 9;
            } else {
              ans += 1 * 1 * c2i(s[k]);
              ans += 1 * c2i(s[j] - 1) * 9;
            }
            ans += c2i(s[i] - 1) * 81;
          } else {
            ans += 9 * 9 * 9;
          }
          flag2 |= s[k] != '0';
        }
        flag1 |= s[j] != '0';
      }
    }
  }
  cout << ans << endl;
  return 0;
}
