import math
def solve(n):
# Calculate integer square root of n and avoid recalculating values
sqrt_n = int(math.isqrt(n))
return min(n
- sqrt_n
* sqrt_n
, (sqrt_n
+ 1) * (sqrt_n
+ 1) - n
)
if __name__ == '__main__':
n = int(input().strip())
print(solve(n))
aW1wb3J0IG1hdGgKCmRlZiBzb2x2ZShuKToKICAgICMgQ2FsY3VsYXRlIGludGVnZXIgc3F1YXJlIHJvb3Qgb2YgbiBhbmQgYXZvaWQgcmVjYWxjdWxhdGluZyB2YWx1ZXMKICAgIHNxcnRfbiA9IGludChtYXRoLmlzcXJ0KG4pKQogICAgcmV0dXJuIG1pbihuIC0gc3FydF9uICogc3FydF9uLCAoc3FydF9uICsgMSkgKiAoc3FydF9uICsgMSkgLSBuKQoKaWYgX19uYW1lX18gPT0gJ19fbWFpbl9fJzoKICAgIG4gPSBpbnQoaW5wdXQoKS5zdHJpcCgpKQogICAgcHJpbnQoc29sdmUobikpCg==