N, M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

pair = []
a.sort!
M.times do
  b, c = gets.split.map(&:to_i)
  pair << [b, c]
end

pair.sort_by! do |d|
  d[1]
end

ci = 0
end_f = false
pair.reverse.each do |d|
  d[0].times do
    if ci >= a.size
      end_f = true
      break
    end

    if a[ci] < d[1]
      a[ci] = d[1]
      ci += 1
    else
      end_f = true
      break
    end
  end
  if end_f
    break
  end
end

p a.inject(:+)