N,M = gets.split(' ').map(&:to_i)
#maze = readlines.map { |line| line.split(' ').map(&:to_i)}
#puts maze[0][0]
As = gets.split(' ').map(&:to_i).sort
#ope = M.times.map{|line| line.split(' ').map(&:to_i)}
bc = M.times.map{ gets.split(' ').map(&:to_i)}
#bc.sort_by!{|x| -x[1] }
#↑↓二番目の要素について降順でソート
bc.sort!{|a,b| b[1]<=>a[1]}

n_cnt = 0
m_cnt = 0
c_cnt = bc[0][0]

while n_cnt<N && m_cnt<M

  if As[n_cnt]>=bc[m_cnt][1]
    n_cnt += 1
  else
    As[n_cnt] = bc[m_cnt][1]
    c_cnt -= 1
    n_cnt += 1
  end
  if c_cnt == 0
    m_cnt+=1
  #  c_cnt = bc[m_cnt][0]
  #  if m_cnt >= M? c_cnt = 0:bc[m_cnt][0]
  if m_cnt >= M
    c_cnt = 0
  else
    c_cnt = bc[m_cnt][0]
  end
end
end
ans = 0
for i in 0..N-1
  ans += As[i]
end
puts ans
