N = int(eval(input()))

ans = []

for i in range(1,int(pow(N,0.5))+1):

    j = N//i

    if i*j == N:

        ans.append(i+j)



print((min(ans)-2))
N = int(eval(input()))

ans = []

for i in range(1,int(pow(N,0.5))+1):

    if N%i==0:

        ans.append(i+N//i)



print((min(ans)-2))
N = int(eval(input()))
ans = []
for i in range(1, int(pow(N, 0.5)) + 1):
    j = N // i
    if i * j == N:
        ans.append(i + j)
print((min(ans) - 2))

N = int(eval(input()))
ans = []
for i in range(1, int(pow(N, 0.5)) + 1):
    if N % i == 0:
        ans.append(i + N // i)
print((min(ans) - 2))

-    j = N // i -    if i * j == N: -        ans.append(i + j) +    if N % i == 0: +        ans.append(i + N // i)