N = int(eval(input()))

N2 = N ** (1 / 2)

ans = float('Inf')

for i in range(1, int(N2) + 1):

    if N % i == 0:

        a = i + N // i - 2

        if ans > a:

            ans = a

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

N_2 = int(N ** 0.5)

ans = float('Inf')

for i in range(1, N_2 + 1):

    if N % i == 0:

        s = i + N / i - 2

        ans = min(ans, int(s))

print(ans)
N = int(eval(input()))
N2 = N ** (1 / 2)
ans = float("Inf")
for i in range(1, int(N2) + 1):
    if N % i == 0:
        a = i + N // i - 2
        if ans > a:
            ans = a
print(ans)

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

-N2 = N ** (1 / 2) +N_2 = int(N**0.5) -for i in range(1, int(N2) + 1): +for i in range(1, N_2 + 1): -        a = i + N // i - 2 -        if ans > a: -            ans = a +        s = i + N / i - 2 +        ans = min(ans, int(s))