import math s = input() n = len(s) S = int(s) k = int(input()) ans = 0 for la inrange(1, n): for lb inrange(1, n - la + 1): al = 10 ** (la - 1) A = al * 10 B = 10 ** lb mxa = A - 1 mxb = B - 1 if la + lb == n : mxa = min(mxa, S // B) p = B * k - 1 q = A - k if p > 0and q > 0: d = math.gcd(p, q) q = q // d p = p // d cnta = mxa // q cntb = mxb // p c = min(cnta, cntb) if c == 0: continue a = q * c b = p * c if al <= a: cur_ans = a * B + b if cur_ans <= S: ans = max(ans, cur_ans) else: a -= q b -= p if al <= a: cur_ans = a * B + b if cur_ans <= S: ans = max(ans,cur_ans) print(ans)