def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
n = int(input())
a = make_divisors(n)
#もっとも近い約数を求める
mid = len(a)//2
#print(a)
#print(a[mid],a[mid-1])
ans = (a[mid-1]-1)+(a[mid]-1)
print(ans)