import math

N = int(eval(input()))

ans = 10**12 + 1

for k in range(1,math.floor(math.sqrt(N))+1):

    if N % k == 0:

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



print(ans)

import math

N = int(eval(input()))

ans = 10**13

for k in range(1,math.floor(math.sqrt(N))+1):

    if N % k == 0:

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

print(ans)

import math

N = int(eval(input()))
ans = 10**12 + 1
for k in range(1, math.floor(math.sqrt(N)) + 1):
    if N % k == 0:
        ans = min(ans, k + N // k - 2)
print(ans)

import math

N = int(eval(input()))
ans = 10**13
for k in range(1, math.floor(math.sqrt(N)) + 1):
    if N % k == 0:
        ans = min(ans, k + N // k - 2)
print(ans)

-ans = 10**12 + 1 +ans = 10**13