nm = STDIN.gets.chomp.split(' ').map(&:to_i)

a = STDIN.gets.chomp.split(' ').map(&:to_i)

inputs = []
nm[1].times do
  inputs << STDIN.gets.chomp.split(' ').map(&:to_i)
end

inputs.each do |array|
  next if a.min > array[1]
  (1..array[0]).each do |_|
    next if a.min > array[1]
    a[a.index(a.min)] = array[1]
  end
end

puts a.inject(:+)
