N = int(eval(input()))



n = int(N**0.5) + 1

A = 0

B = 0

b = 0

for a in range(1, n):

    if N % a == 0:

        b = N // a

        A = a

        B = b

ans = (A - 1) + (B - 1)

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



n = int(N**0.5) + 1



for a in range(1, n):

    if N % a == 0:

        b = N // a

        ans = (a - 1) + (b - 1)

print(ans)
N = int(eval(input()))
n = int(N**0.5) + 1
A = 0
B = 0
b = 0
for a in range(1, n):
    if N % a == 0:
        b = N // a
        A = a
        B = b
ans = (A - 1) + (B - 1)
print(ans)

N = int(eval(input()))
n = int(N**0.5) + 1
for a in range(1, n):
    if N % a == 0:
        b = N // a
        ans = (a - 1) + (b - 1)
print(ans)

-A = 0 -B = 0 -b = 0 -        A = a -        B = b -ans = (A - 1) + (B - 1) +        ans = (a - 1) + (b - 1)