import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] base = in.nextLine().split(" ");
int n = Integer.valueOf(base[0]);
int m = Integer.valueOf(base[1]);
//货物
String[] shops = in.nextLine().split(" ");
String[] helpers = new String[m];
for (int i = 0; i < m; i ++){
helpers[i] = in.nextLine();
}
int result = 0;
int[][] money = new int[m][4];
Set<Integer> check = new HashSet<>();
for (int i = 0; i < m; i ++){
String[] temp = helpers[i].split(" ");
money[i][1] = Integer.valueOf(temp[0]);
//优惠
money[i][0] = Integer.valueOf(temp[1]);
}
sortIntArray(money,new int[] {0,1});
int[] helpShow = new int[n];
for (int i = 0; i < n; i ++) {
helpShow[i] = Integer.valueOf(shops[i]);
result += helpShow[i];
}
Arrays.sort(helpShow);
for (int i = 0; i < n; i ++){
for (int j = m - 1; j >= 0; j --){
if (money[j][1] <= helpShow[i] && !check.contains(j)){
result -= money[j][0];
check.add(j);
break;
}
}
}
System.out.println(result);
}
private static void sortIntArray(int[][] arObjects, final int[] arOrders)
{
Arrays.sort(arObjects, new Comparator<Object>()
{
public int compare(Object oObjectA, Object oObjectB)
{
int[] arTempOne = (int[])oObjectA;
int[] arTempTwo = (int[])oObjectB;
for (int i = 0; i < arOrders.length; i++)
{
int k = arOrders[i];
if (arTempOne[k] > arTempTwo[k])
{
return 1;
}
else if (arTempOne[k] < arTempTwo[k])
{
return -1;
}
else
{
continue;
}
}
return 0;
}
});
}
}
好渔夫的一个方法