n=int(eval(input()))



ans=10**12

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

    if n%i==0:

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

print(ans)
n=int(eval(input()))



num=int(n**0.5)

ans=float('inf')

for i in range(1,num+1):

    if n%i==0:

        temp=i+n//i-2

        if temp<ans:ans=temp



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

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

-ans = 10**12 -for i in range(1, int(n**0.5) + 1): +num = int(n**0.5) +ans = float("inf") +for i in range(1, num + 1): -        ans = min(ans, i + n // i - 2) -print(ans) +        temp = i + n // i - 2 +        if temp < ans: +            ans = temp +print(temp)