n=int(eval(input()))



def divisor(n): 

    i = 1

    table = []

    while i * i <= n:

        if n%i == 0:

            table.append(i)

            table.append(n//i)

        i += 1

    table = list(set(table))

    return table



a=divisor(n)

a.sort()



c=[]

for i in range(len(a)//2+1):

    d=a[i]-1+a[-i-1]-1

    c.append(d)



print((min(c)))
import sys



n=int(eval(input()))



c=[]



for i in range(2,int(n**(1/2))+1):

    if n%i==0:

        c.append(i+n//i-2)



if len(c)==0:

    print((n-1))

    sys.exit()

    

print((min(c)))
n = int(eval(input()))


def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


a = divisor(n)
a.sort()
c = []
for i in range(len(a) // 2 + 1):
    d = a[i] - 1 + a[-i - 1] - 1
    c.append(d)
print((min(c)))

import sys

n = int(eval(input()))
c = []
for i in range(2, int(n ** (1 / 2)) + 1):
    if n % i == 0:
        c.append(i + n // i - 2)
if len(c) == 0:
    print((n - 1))
    sys.exit()
print((min(c)))

+import sys + - - -def divisor(n): -    i = 1 -    table = [] -    while i * i <= n: -        if n % i == 0: -            table.append(i) -            table.append(n // i) -        i += 1 -    table = list(set(table)) -    return table - - -a = divisor(n) -a.sort() -for i in range(len(a) // 2 + 1): -    d = a[i] - 1 + a[-i - 1] - 1 -    c.append(d) +for i in range(2, int(n ** (1 / 2)) + 1): +    if n % i == 0: +        c.append(i + n // i - 2) +if len(c) == 0: +    print((n - 1)) +    sys.exit()