require 'prime'

n = gets.to_i

sq = Math.sqrt(n)
result = 0
if sq % 1 == 0
    result = (sq - 1) * 2
elsif Prime.prime?(n)
    result = n - 1
else
    (sq.to_i..n).each do |i|
        (1..sq.to_i).each do |j|
            k = sq.to_i - j
            if i * j == n
                result = i + j - 2
                break
            end
        end
        break if result != 0
    end
end

puts result