n = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n = int(n/i)
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

l = prime_decomposition(n)
l.append(1)
l.sort()
l.reverse()
a = 1
b = 1

for i in range(len(l)):
    if a <= b:
        a *= l[len(l)-1-i]
    else:
        b *= l[len(l)-1-i]

print(a+b-2)