#include <bits/stdc++.h>
using namespace std;
const int NN = 30;
pair<int, int> nex[NN][NN][3];
int dp[NN][NN][3];
vector<int> s;
void to_dig(vector<int> &A, long long x) {
  A.clear();
  do {
    A.push_back(x % 10);
    x /= 10;
  } while (x);
  return;
}
int rec(int rem, int start, int small) {
  if (rem == -1) return 1;
  int &res = dp[rem][start][small];
  if (~res) return res;
  res = 0;
  for (int dig = 9; dig >= 0; dig--) {
    if (rem <= start - 1 && dig != 9) continue;
    int n_small = small;
    if (small == 0 && dig > s[rem]) continue;
    if (dig < s[rem]) n_small = 1;
    if (rec(rem - 1, start, n_small)) {
      nex[rem][start][small] = make_pair(dig, n_small);
      return res = 1;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  long long A, B;
  cin >> A >> B;
  s.clear();
  to_dig(s, A);
  long long ans = -1;
  memset(dp, -1, sizeof(dp));
  for (int nine = 0; nine < 20; nine++) {
    int can = rec(((int)s.size()) - 1, nine, 0);
    if (can) {
      long long found = 0;
      int small = 0;
      for (int rem = ((int)s.size()) - 1; rem >= 0; rem--) {
        pair<int, int> p = nex[rem][nine][small];
        small = p.second;
        found = found * 10 + p.first;
      }
      if (A - found <= B) {
        ans = found;
      }
    }
  }
  cout << ans << endl;
}
