n=int(eval(input()))

ans=n

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

    if n%i==0:

        ans=n//i+i-2

print(ans)

n=int(eval(input()))

ans=0

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

    if n%i==0:

        ans=n//i+i-2

print(ans)

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

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

-ans = n +ans = 0