#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
  os << "(" << p.first << ": " << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << "(";
  for (auto& i : v) os << i << ", ";
  os << ")";
  return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, map<K, V> m) {
  os << "{";
  for (auto& i : m) os << i << ", ";
  os << "}";
  return os;
}
int main() {
  string n;
  long long k;
  cin >> n >> k;
  string s = n;
  reverse(s.begin(), s.end());
  long long ans = 0;
  if (k == 1) {
    for (long long i = 0; i < s.size(); ++i) {
      auto a = s[i] - '0';
      ans += a;
      if (i != s.size() - 1) {
        ans += 9;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (k == 2) {
    for (long long i = 0; i < s.size(); ++i) {
      for (long long j = i + 1; j < s.size(); ++j) {
        auto a = s[i] - '0';
        auto b = s[j] - '0';
        if (i == s.size() - 2 && j == s.size() - 1) {
          ans += a;
          ans += (b - 1) * 9;
        } else if (j == s.size() - 1) {
          ans += 9;
          ans += (b - 1) * 9;
        } else {
          ans += 81;
        }
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (k == 3) {
    for (long long i = 0; i < s.size(); ++i) {
      for (long long j = i + 1; j < s.size(); ++j) {
        for (long long k = j + 1; k < s.size(); ++k) {
          auto a = s[i] - '0';
          auto b = s[j] - '0';
          auto c = s[k] - '0';
          if (i == s.size() - 3 && j == s.size() - 2 && k == s.size() - 1) {
            ans += a;
            ans += (b - 1) * 9;
            ans += (c - 1) * 81;
          } else if (j == s.size() - 2 && k == s.size() - 1) {
            ans += 9;
            ans += (b - 1) * 9;
            ans += (c - 1) * 81;
          } else if (k == s.size() - 1) {
            ans += 81;
            ans += (c - 1) * 81;
          } else {
            ans += 729;
          }
        }
      }
    }
    cout << ans << endl;
    return 0;
  }
  return 0;
}
