# N

n = gets.chomp.to_i

def eratosthenes_sieve(n)
  check = Array.new(n, false)
  primes = []

  (2..n).each do |i|
    if !check[i]
      primes << i

      (i..n).step(i).each do |j|
        check[j] = true
      end
    end
  end

  primes
end

def prime_factorization(n)
  m = n
  result = []
  primes = eratosthenes_sieve(Math.sqrt(n).ceil)

  while true
    found = false

    primes.each do |pr|
      if m % pr == 0
        result << pr
        found = true
        m = m / pr
        break
      end
    end

    if !found
      result << m if m != 1
      break
    end
  end

  result
end

factors = prime_factorization(n)
c = factors.count
b = 2 ** c - 1

r = []

for i in 0..b
  r1 = 1
  r2 = 1

  for j in 0...c do
    if i[j] == 1
      r1 = r1 * factors[j]
    else
      r2 = r2 * factors[j]
    end
  end

  r << (r1 + r2)
end

puts r.min - 2
