You have N cards. On the i-th card, an integer A_i is written.

For each j = 1, 2, ..., M in this order, you will perform the following operation once:

Operation: Choose at most B_j cards (possibly zero). Replace the integer written on each chosen card with C_j.

Find the maximum possible sum of the integers written on the N cards after the M operations.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq A_i, C_i \leq 10^9
* 1 \leq B_i \leq N

Input

Input is given from Standard Input in the following format:


N M
A_1 A_2 ... A_N
B_1 C_1
B_2 C_2
\vdots
B_M C_M


Output

Print the maximum possible sum of the integers written on the N cards after the M operations.

Examples

Input

3 2
5 1 4
2 3
1 5


Output

14


Input

10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4


Output

338


Input

3 2
100 100 100
3 99
3 99


Output

300


Input

11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000


Output

10000000001
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static long[] cards;
	static long[][] jyouken;
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		cards=new long[N];
		for(int i=0; i<N; i++) {
			cards[i]=sc.nextLong();
		}
		Arrays.sort(cards);
		jyouken=new long[M][2];
		for(int i=0; i<M; i++) {
			jyouken[i][0]=sc.nextLong();
			jyouken[i][1]=sc.nextLong();
		}
		/*
		 * 変更できるのが充分でかい場合全部して
		 * そうでなければ一部だけ
		 */
		quick_sort(jyouken,0,M-1);
		//これ二分探索だわ
		long tmp=cards[N-1];
		long sum=0;
		for(int i=M-1; i>=0; i--) {
			if(jyouken[i][1]>=tmp) {
				sum+=jyouken[i][0];
			}
		}
		if(sum>=N) {	//更新できるものが沢山の時
			long ans=0;
			long cnt=0;
			for(int i=M-1; i>=0; i--) {
				if(cnt<N) {
					if(cnt+jyouken[i][0]<=N) {
						ans+=jyouken[i][0]*jyouken[i][1];
						cnt+=jyouken[i][0];
					}
					else if(cnt+jyouken[i][0]>N) {
						ans+=jyouken[i][1]*(((long)N)-cnt);
						cnt=N;
					}
				}
				else {
					break;
				}
			}
			pl(ans);
		}
		else {
			int counter=0;
			for(int i=M-1; i>=0; i--) {
				if(counter<N) {
					for(int j=0; j<jyouken[i][0]; j++) {
						if(counter<N) {
							if(cards[counter]<jyouken[i][1]) {
								cards[counter]=jyouken[i][1];
								counter++;
							}
							else {
								break;
							}
						}
						else {
							break;
						}
					}
				}
				else {
					break;
				}
			}
			long ans=0;
			for(int i=0; i<N; i++) {
				ans+=cards[i];
			}
			pl(ans);
			/*for(int i=0; i<N; i++) {
				pl(cards[i]);
			}*/
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static void quick_sort(long[][] d, int left, int right) {
		if (left>=right) {
			return;
		}
		long p = d[(left+right)/2][1];
		int l = left, r = right;
		long tmp,tmp1,tmp2;
		while(l<=r) {
			while(d[l][1] < p) { l++; }
			while(d[r][1] > p) { r--; }
			if (l<=r) {
				tmp = d[l][1]; d[l][1] = d[r][1]; d[r][1] = tmp;
				tmp1=d[l][0]; tmp2=d[r][0]; d[l][0]=tmp2; d[r][0]=tmp1;
				l++; r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}