from bisect import bisect_left as bl M = 2 * 10**6 r = [i * i for i in range(M)] D = int(input()) ans = M + 10 for x in range(M): p = bl(r, D - x * x) yy1 = r[p - 1] yy2 = r[p] yy3 = r[p + 1] wk = min(abs(D - x * x - yy1), abs(D - x * x - yy2), abs(D - x * x - yy3)) ans = min(ans, wk) print(ans)