N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [list(map(int, input().split())) for _ in range(M)]

# n番目の要素でソートsort
BC = sorted(BC, reverse=True, key=lambda x: x[1])

m = A[0]
D = []
for b, c in BC:
    if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
    if len(D) > N:
        break

D.append(0)

for i, d in enumerate(D):
    if i >= N:
        break
    if A[i] < d:
        A[i] = d
    else:
        break

print(sum(A)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(list(map(int, input().split()))) A sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [list(map(int, input().split())) for _ in range(M)] BC [list(map(int, input().split())) for _ in range(M)] BC = sorted(BC, reverse=True, key=lambda x: x[1]) BC sorted(BC, reverse=True, key=lambda x: x[1]) sorted BC reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x m = A[0] m A[0] A 0 D = [] D [] for b, c in BC:
    if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
    if len(D) > N:
        break b c BC if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
     c > m c m D.append(c) for i in range(b) for i in range(b) i range(b) range b for i in range(b) D.append(c) D.append D append c _ = [D.append(c) for i in range(b)] _ [D.append(c) for i in range(b)] continue if len(D) > N:
        break len(D) > N len(D) len D N break D.append(0) D.append D append 0 for i, d in enumerate(D):
    if i >= N:
        break
    if A[i] < d:
        A[i] = d
    else:
        break i d enumerate(D) enumerate D if i >= N:
        break
     i >= N i N break if A[i] < d:
        A[i] = d
    else:
        break A[i] < d A[i] A i d A[i] = d A[i] A i d break print(sum(A)) print sum(A) sum A A = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) A BC = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] BC D = [] [] D _ = [D.append(c) for i in range(b)] [D.append(c) for i in range(b)] _ BC = sorted(BC, reverse=True, key=lambda x: x[1]) sorted(BC, reverse=True, key=lambda x: x[1]) BC M = map(int, input().split()) map(int, input().split()) M m = A[0] A[0] m N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [list(map(int, input().split())) for _ in range(M)]

# n番目の要素でソートsort
BC = sorted(BC, reverse=True, key=lambda x: x[1])

m = A[0]
D = []
for b, c in BC:
    if c > m:
        _ = [D.append(c) for i in range(b)]
    else:
        continue
    if len(D) > N:
        break

D.append(0)

for i, d in enumerate(D):
    if i >= N:
        break
    if A[i] < d:
        A[i] = d
    else:
        break

print(sum(A))
