// D - Integer Cards
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const NM = input.shift().split(' ').map(val => Number(val))
  const cards = input.shift().split(' ')
    .map(val => Number(val)).sort((a, b) => a - b)
  input = input.map(val => val.split(' ').map(val => Number(val)))
    .sort((a, b) => b[1] - a[1])
  
  let start = 0;
  for (let i = 0; i < input.length; i++) {
    let count = input[i][0]
    for (let j = start; j < cards.length; j++) {
      if (cards[j] < input[i][1]) {
        cards[j] = input[i][1]
        count--;
        start = j + 1
        if (count === 0) break;
      } else {
        break;
      }
    }
  }
  console.log(cards.reduce((p, c) => p + c))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
