n = int(input())
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
  
ans = n
yakusuu = make_divisors(n)
for i in range(0 ,len(yakusuu), 2):
    kari = yakusuu[i] -1 + yakusuu[i+1]-1
    if (ans > kari):
        ans = kari
print(ans)