#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.first << ',' << P.second << ')';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int x;
  cin >> x;
  long long int n = s.size();
  long long int nxt[n + 1];
  nxt[n] = n;
  for (long long int i = n - 1; i >= 0; i--) {
    nxt[i] = nxt[i + 1];
    if (s[i] != '0') nxt[i] = i;
  }
  long long int ans = 0;
  if (x == 3) {
    for (long long int i = 0; i < (n); i++) {
      for (long long int j = i + 1; j < n; j++) {
        for (long long int k = j + 1; k < n; k++) {
          if (i) {
            ans += 9 * 9 * 9;
          } else {
            ans += (max(0, s[i] - '0' - 1)) * 9 * 9;
            if (j <= nxt[i + 1]) {
              ans += (max(0, s[j] - '0' - 1)) * 9;
              if (nxt[j + 1] >= k) {
                ans += s[k] - '0';
              } else {
                ans += 9;
              }
            } else {
              ans += 9 * 9;
            }
          }
        }
      }
    }
  } else if (x == 2) {
    for (long long int i = 0; i < (n); i++) {
      for (long long int j = i + 1; j < n; j++) {
        if (i) {
          ans += 9 * 9;
        } else {
          ans += max(s[i] - '0' - 1, 0) * 9;
          if (j <= nxt[i + 1]) {
            ans += (s[j] - '0');
          } else {
            ans += 9;
          }
        }
      }
    }
  } else {
    for (long long int i = 0; i < (n); i++) {
      if (i) {
        ans += 9;
      } else {
        ans += (s[i] - '0');
      }
    }
  }
  cout << ans << '\n';
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  ;
}
