N=int(eval(input()))

move=int(N**.5)

while N%move!=0:

    move-=1

print((N//move+move-2))
N=int(eval(input()))

move=10**12

for n in range(1,int(N**.5)+1):

    if N%n==0:

        move=min(move,N//n+n-2)

print(move)
N = int(eval(input()))
move = int(N**0.5)
while N % move != 0:
    move -= 1
print((N // move + move - 2))

N = int(eval(input()))
move = 10**12
for n in range(1, int(N**0.5) + 1):
    if N % n == 0:
        move = min(move, N // n + n - 2)
print(move)

-move = int(N**0.5) -while N % move != 0: -    move -= 1 -print((N // move + move - 2)) +move = 10**12 +for n in range(1, int(N**0.5) + 1): +    if N % n == 0: +        move = min(move, N // n + n - 2) +print(move)