n = int(eval(input()))

min1 = 10**20

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

  if n/i %1 == 0:

    j = n//i

    min1 = min(min1,i+j)

print((min1-2))
n = int(eval(input()))

ans = 10**13

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

    if n%i == 0:

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

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

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

-min1 = 10**20 -for i in range(1, int(n**0.5) + 1): -    if n / i % 1 == 0: -        j = n // i -        min1 = min(min1, i + j) -print((min1 - 2)) +ans = 10**13 +for i in range(1, int(n**0.5 // 1) + 1): +    if n % i == 0: +        ans = min(ans, i + n // i - 2) +print(ans)