N = int(eval(input()))

ans = 10 ** 19

for i in range(1, int(N**.5) + 1):

  if N % i == 0:

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

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

for i in range(int(n**.5) + 1, 0, -1):

  if n % i == 0:

    ans = n // i + i - 2

    print(ans)

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

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

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