N = int(eval(input()))



a, b = 1, N

for n in range(2,N):

    if n*n == N:

        a = b = n

        break

    elif n*n > N:

        break

    elif N%n == 0:

        a, b = n, N//n



print((a+b-2))
N=int(eval(input()))

ans = 10**12

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

    if N%n==0:

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

print(ans)
N = int(eval(input()))
a, b = 1, N
for n in range(2, N):
    if n * n == N:
        a = b = n
        break
    elif n * n > N:
        break
    elif N % n == 0:
        a, b = n, N // n
print((a + b - 2))

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

-a, b = 1, N -for n in range(2, N): -    if n * n == N: -        a = b = n -        break -    elif n * n > N: -        break -    elif N % n == 0: -        a, b = n, N // n -print((a + b - 2)) +ans = 10**12 +for n in range(1, int(N**0.5) + 1): +    if N % n == 0: +        ans = min(ans, n + N // n - 2) +print(ans)