import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val N, M = sc.nextInt()
    val As = List.fill(N)(sc.nextLong).sorted
    val l = List.fill(M, 2)(sc.nextLong).map(a => (a.head.toInt, a.tail.head))

    val ls = l.foldLeft(List.fill(N)(0L)) {
      case (pre, (num, v)) =>
        val (less, remain) = pre.sorted.splitAt(num)
        less.map(a => if (a < v) v else a) ::: remain
    }

    val r = ls.foldLeft(As) {
      case (pre, v) =>
        (v :: pre).sorted.tail
    }
    
    println(r.sum)
  }
}