def var_calc(n): var = 0 for i in range(1, n + 1): var += i * i return var def shirabe(n): var = 0 for i in range(1, n + 1): var += i * i a = [0] * (var + 1) a[0] = 1 for i in range(1, n + 1): b = a[::] for j in range(var + 1): if i * i + j <= var and a[j]: b[i * i + j] = 1 a = b tar = [] for i in range(var + 1): if a[i] == 0: tar.append(i) return tar # 1 + 4 + 9 + 16 + 25 + 36 #for n in range(1, 11): # print(n, shirabe(n), var_calc(n)) umekomi = [2, 3, 6, 7, 8, 11, 12, 15, 18, 19, 22, 23, 24, 27, 28, 31, 32, 33, 43, 44, 47, 48, 60, 67, 72, 76, 92, 96, 108, 112, 128] r, b = map(int,input().split()) ub = 2 * 10 ** 6 lb = 1 while ub - lb > 1: t = (ub + lb) // 2 av = var_calc(t) if r + b < av: ub = t continue norep = set(umekomi) for i in umekomi: norep.add(av - i) if r >= av or b >= av: lb = t continue good = 0 for i in range(0, min(r+1, 1000)): if r - i in norep: continue if av - (r - i) > b: continue if av - (r - i) < 0: continue if av - (r - i) in norep: continue good = 1 break if good: lb = t else: ub = t print(lb)