fun main(x:Array<String>) {
  val (n,m) = readLine()!!.split(" ").map(String::toInt)
  val a = readLine()!!.split(" ").map(String::toInt).toMutableList()
  var l : MutableList<List<Int>> = mutableListOf()
  for (i in 0..m-1) {
    l.add(readLine()!!.split(" ").map(String::toInt))
  }
  a.sort()
  l.sortBy {-it[1]}
  var ans = 0L
  var idx = 0
  run loop@ {
    l.forEach {
      for ( i in 0..it[0]-1) {
	    if (it[1] <= a[idx]) return@loop
        a[idx] = it[1]
        idx++
        if (idx >= a.size) return@loop
      }
    }
  }
  
  a.forEach {ans += it}
  println(ans)
  
}