#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;
template <typename T>
inline void dbg(T a) {
  cout << setprecision(12) << a << ' ';
}
ll n, m, k, l, ans = 0, sum = 0, cnt = 0;
string s;
char c;
int main() {
  cin >> n >> k;
  vi a((ll)log10(n) + 1, 0);
  m = a.size() - 1;
  for (ll i = (ll)(0); i < (ll)(k); ++i) a[m - i] = 1;
  s = to_string(n);
  do {
    if (a[0] == 0) {
      sum += pow(9, k);
    } else {
      for (ll i = (ll)(1); i < (ll)(a.size()); ++i) {
        if (a[i] == 0 && (int)s[i] > 0) {
          sum += pow(9, k - i);
          break;
        } else if (a[i] > 0 && (int)s[i] == 0) {
          cout << setprecision(12) << sum << endl;
          return 0;
        } else {
          dbg(2);
          if (i == m) {
            for (ll j = (ll)(0); j < (ll)(a.size()); ++j) {
              sum += (int)s[n - 1 - j] * pow(10, j);
            }
          }
        }
      }
    }
  } while (next_permutation(a.begin(), a.end()));
  cout << setprecision(12) << sum << endl;
}
