n = gets.chomp.to_i

def min_divisors(n)
    divisors = []
    (2..(n/2).to_i).each do |i|
        if n % i == 0
            divisors << [i, n/i]
        end
    end
    divisors
end

puts min_divisors(n).map{ |i, j| i + j }.min - 2