require 'prime'

n = gets.chomp.to_i
prime = n.prime_division
a = []
for i in 0..(prime.length - 1)
  for k in 1..prime[i][1]
    a.push(prime[i][0])
  end
end
m = a[a.length - 1]
min = n
for i in 0..(a.length - 1)
  if (m + n / m) > m + a[a.length - 1 - i] + n / m + a[a.length - 1 - i]
    m += a[a.length - 1 - i]
  end
end
puts m + n / m - 2