n=int(eval(input()))

ans=float('inf')

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

  if n%i==0:

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

print(ans)

n=int(eval(input()))

ans=float('inf')

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

    if n%i==0:

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

print(ans)

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

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

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