require "prime"
N = gets.chomp.to_i
f = N.prime_division.map do |n, k|
  [n] * k
end.flatten.sort

c = []
1.upto(f.size) do |n|
  f.combination(n).each do |vs|
    v = vs.inject(&:*)
    rest = N / v
    c << v + rest - 2
  end
end
puts c.min
