object Main extends App {

  val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  var a = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList.sorted

  (1 to m).foreach { _ =>
    val Array(b, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    /*
     val rr = a.filter(_ < c)
     println("rr:" + rr)
     if (rr.length <= b) {
       val aa = a.drop(rr.length)
       a = aa.filter(_ < c) ::: List.fill(rr.length)(c) ::: aa.filter(_ >= c)
     } else {
       val aa = a.drop(b)
       a = aa.filter(_ < c) ::: List.fill(b)(c) ::: aa.filter(_ >= c)
     }
     println(a)
     */
    val dropcnt = List(a.count(_ < c), b).min
    val aa = a.drop(dropcnt)
    a = aa.filter(_ < c) ::: List.fill(dropcnt)(c) ::: aa.filter(_ >= c)
  }
  println(a.map(_.toLong).sum)


  /*
    var tree = scala.collection.immutable.TreeSet.empty[Long]
    val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a = scala.io.StdIn.readLine.split(" ").map(_.toLong)
    tree = tree ++ a

    (1 to m).foreach { _ =>
      val Array(b, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
      val rr = tree range(1, c)
      println("rr:" + rr)
      if (rr.size <= b) {
        tree = tree.drop(rr.size) ++ List.fill(rr.size)(c.toLong)
      } else {
        val ee: List[Long] = List.fill(b)(c.toLong)
        println(tree.drop(b) ++ ee.toSet)
        tree = tree.drop(b) ++ List.fill(b)(c.toLong)
      }
      println(tree)
    }

    println(tree.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)

   */
}