require 'prime'

n = gets.chomp.to_i

factors = n.prime_division
if factors.size == 1
  puts n-1
  exit
end

min = Float::INFINITY
factors.each do |factor|
  (0..factor[1]).each do |f|
    a = factor[0] ** f
    b = n / a
    min = [min, a + b - 2].min
  end
end
puts min
