from sys import stdin
import collections

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
A = collections.Counter(A)
for i in range(M):
    B, C = [int(x) for x in stdin.readline().rstrip().split()]
    A[C] += B 
A = dict(A)
A = dict(sorted(A.items()))

S = 0
j = -1

A_key = list(A.keys())
A_value = list(A.values())

while True:
    if A_value[j] < N:
        S += A_value[j] * A_key[j]
        N -= A_value[j]
        j -= 1
    else:
        S += N * A_key[j]
        break
print(S) from sys import stdin import collections collections int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x N, M = [int(x) for x in stdin.readline().rstrip().split()] N [int(x) for x in stdin.readline().rstrip().split()] M int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x A = [int(x) for x in stdin.readline().rstrip().split()] A [int(x) for x in stdin.readline().rstrip().split()] A = collections.Counter(A) A collections.Counter(A) collections.Counter collections Counter A for i in range(M):
    B, C = [int(x) for x in stdin.readline().rstrip().split()]
    A[C] += B  i range(M) range M int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x B, C = [int(x) for x in stdin.readline().rstrip().split()] B [int(x) for x in stdin.readline().rstrip().split()] C A[C] += B A[C] A C B A = dict(A) A dict(A) dict A A = dict(sorted(A.items())) A dict(sorted(A.items())) dict sorted(A.items()) sorted A.items() A.items A items S = 0 S 0 j = -1 j -1 A_key = list(A.keys()) A_key list(A.keys()) list A.keys() A.keys A keys A_value = list(A.values()) A_value list(A.values()) list A.values() A.values A values while True:
    if A_value[j] < N:
        S += A_value[j] * A_key[j]
        N -= A_value[j]
        j -= 1
    else:
        S += N * A_key[j]
        break True if A_value[j] < N:
        S += A_value[j] * A_key[j]
        N -= A_value[j]
        j -= 1
    else:
        S += N * A_key[j]
        break A_value[j] < N A_value[j] A_value j N S += A_value[j] * A_key[j] S A_value[j] * A_key[j] A_value[j] A_value j A_key[j] A_key j N -= A_value[j] N A_value[j] A_value j j -= 1 j 1 S += N * A_key[j] S N * A_key[j] N A_key[j] A_key j break print(S) print S N, M = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] N S += N * A_key[j] N * A_key[j] S A_value = list(A.values()) list(A.values()) A_value j -= 1 1 j M = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] M A = dict(A) dict(A) A A = dict(sorted(A.items())) dict(sorted(A.items())) A B, C = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] B A = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] A A = collections.Counter(A) collections.Counter(A) A A_key = list(A.keys()) list(A.keys()) A_key j = -1 -1 j C = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] C S += A_value[j] * A_key[j] A_value[j] * A_key[j] S N -= A_value[j] A_value[j] N S = 0 0 S
from sys import stdin
import collections

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
A = collections.Counter(A)
for i in range(M):
    B, C = [int(x) for x in stdin.readline().rstrip().split()]
    A[C] += B 
A = dict(A)
A = dict(sorted(A.items()))

S = 0
j = -1

A_key = list(A.keys())
A_value = list(A.values())

while True:
    if A_value[j] < N:
        S += A_value[j] * A_key[j]
        N -= A_value[j]
        j -= 1
    else:
        S += N * A_key[j]
        break
print(S)
