n = int(eval(input()))

i = int(n**(1/2))

while n%i:

	i-=1

j = n//i

ans = (i - 1) + (j - 1)

#print(i,j)

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

for i in range(1,int(n**(1/2)+1))[::-1]:

    if not n%i:

        j = n//i 

        print((i-1+j-1))

        break

n = int(eval(input()))
i = int(n ** (1 / 2))
while n % i:
    i -= 1
j = n // i
ans = (i - 1) + (j - 1)
# print(i,j)
print(ans)

n = int(eval(input()))
for i in range(1, int(n ** (1 / 2) + 1))[::-1]:
    if not n % i:
        j = n // i
        print((i - 1 + j - 1))
        break

-i = int(n ** (1 / 2)) -while n % i: -    i -= 1 -j = n // i -ans = (i - 1) + (j - 1) -# print(i,j) -print(ans) +for i in range(1, int(n ** (1 / 2) + 1))[::-1]: +    if not n % i: +        j = n // i +        print((i - 1 + j - 1)) +        break