require 'prime'
n = gets.to_i
move_counts = []
if Prime.prime?(n)
    move_counts << n - 1
else
    (2..Math.sqrt(n).to_i).each do |a|
        ((n / 2)..Math.sqrt(n).to_i).each do |b|
            if a * b == n
                move_counts << a + b - 2 if a + b - 2 > 0
            end
        end
    end
end
puts move_counts.min