object Main extends App {

  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val a = scala.io.StdIn.readLine.split(" ").map(_.toLong)
  val pq = new mutable.PriorityQueue[Long]()(Ordering.Long.reverse)

  a.foreach(pq.enqueue(_))
  println(pq)
  (1 to m).foreach { _ =>
    val Array(b, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    (1 to b).foreach { _ =>
    //  println(pq)
      pq.enqueue(List(pq.dequeue, c).max)
    }
  }

  println(pq.sum)
  /*

  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var a = scala.io.StdIn.readLine.split(" ").map(_.toLong).sorted
  (1 to m).foreach { _ =>
    val Array(b, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    (1 to b).foreach { _ =>
      if (a.head < c) {
        a = (c.toLong +: a.tail).sorted
      }
     // println(a.deep)
    }
  }


  println(a.sum)

   */
}