n = int(eval(input()))



ans = n - 1

for i in range(2, n):

    if i * i > n:

        break



    if n % i == 0:

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



print(ans)

n = int(eval(input()))



ans = n - 1

for i in range(1, n):

    if i * i > n:

        break

    if n % i != 0:

        continue

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



print(ans)

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

n = int(eval(input()))
ans = n - 1
for i in range(1, n):
    if i * i > n:
        break
    if n % i != 0:
        continue
    ans = min(ans, i + (n // i) - 2)
print(ans)

-for i in range(2, n): +for i in range(1, n): -    if n % i == 0: -        ans = min(ans, i + n // i - 2) +    if n % i != 0: +        continue +    ans = min(ans, i + (n // i) - 2)