N = int(eval(input()))



x = int(N ** 0.5)



for i in range(x):

    if N % x == 0:

        y = N // x

        break

    x -= 1



ans = x + y - 2



print(ans)

N = int(eval(input()))



x = int(N ** 0.5)



for i in range(x, 0, -1):

    if N % i == 0:

        y = N // i

        break



ans = N // y + y - 2



print(ans)

N = int(eval(input()))
x = int(N**0.5)
for i in range(x):
    if N % x == 0:
        y = N // x
        break
    x -= 1
ans = x + y - 2
print(ans)

N = int(eval(input()))
x = int(N**0.5)
for i in range(x, 0, -1):
    if N % i == 0:
        y = N // i
        break
ans = N // y + y - 2
print(ans)

-for i in range(x): -    if N % x == 0: -        y = N // x +for i in range(x, 0, -1): +    if N % i == 0: +        y = N // i -    x -= 1 -ans = x + y - 2 +ans = N // y + y - 2