n=int(eval(input()))

ans=n-1

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

    if n % i == 0:

        tmp=i+n//i-2

        ans=min(ans,tmp)

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

ans=n-1

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

    if n%i==0:

        tmp=i+n//i-2

        ans=min(ans,tmp)

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

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

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