N=int(eval(input()))

dmin = 10**12+10

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

    if N%i==0:

        n = N//i

        dmin = min(dmin,i-1+n-1)

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

dmin = N+N

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

    if N%i==0:

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

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

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

-dmin = 10**12 + 10 +dmin = N + N -        n = N // i -        dmin = min(dmin, i - 1 + n - 1) +        dmin = min(dmin, i + N // i - 2)