n=int(eval(input()))

ans=float('inf')

a=1

while n**0.5>=a:

  if n%a==0:

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

  a+=1

print(ans)

n=int(eval(input()))

ans=float('inf')

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

  if n%a==0:

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

print(ans)

n = int(eval(input()))
ans = float("inf")
a = 1
while n**0.5 >= a:
    if n % a == 0:
        ans = min(ans, a + n // a - 2)
    a += 1
print(ans)

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

-a = 1 -while n**0.5 >= a: +for a in range(1, int(n**0.5 + 1)): -    a += 1