N, M = map(int,input().split())
A = sorted(list(map(int, input().split())))
p = [ list(map(int, input().split())) for i in range(M) ]
p = sorted(p, reverse=True, key=lambda x: x[1])

maxv = max(A)
minv = min(A)
ans = sum(A)

if p[0][1] < minv:
    print(ans)
else:
    cnt = 0
    j = 0
    i = 0
    for x in p:
        while(i < min(j + x[0], N)):
            if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
        else:
            j = i
            if j >= N:
                break
            continue
        break
    print(ans) 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 i in range(M) for i in range(M) i range(M) range M for i in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split p = [ list(map(int, input().split())) for i in range(M) ] p [ list(map(int, input().split())) for i in range(M) ] p = sorted(p, reverse=True, key=lambda x: x[1]) p sorted(p, reverse=True, key=lambda x: x[1]) sorted p reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x maxv = max(A) maxv max(A) max A minv = min(A) minv min(A) min A ans = sum(A) ans sum(A) sum A if p[0][1] < minv:
    print(ans)
else:
    cnt = 0
    j = 0
    i = 0
    for x in p:
        while(i < min(j + x[0], N)):
            if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
        else:
            j = i
            if j >= N:
                break
            continue
        break
    print(ans) p[0][1] < minv p[0][1] [0] p 0 1 minv print(ans) print ans cnt = 0 cnt 0 j = 0 j 0 i = 0 i 0 for x in p:
        while(i < min(j + x[0], N)):
            if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
        else:
            j = i
            if j >= N:
                break
            continue
        break
     x p while(i < min(j + x[0], N)):
            if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
        else:
            j = i
            if j >= N:
                break
            continue
         i < min(j + x[0], N) i min(j + x[0], N) min j + x[0] j x[0] x 0 N if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
         x[1] > A[i] x[1] x 1 A[i] A i ans = ans - A[i] + x[1] ans ans - A[i] + x[1] ans - A[i] ans A[i] A i x[1] x 1 i = i+1 i i+1 i 1 break j = i j i if j >= N:
                break
             j >= N j N break continue break print(ans) print ans A = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) A i = i+1 i+1 i N, M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M ans = sum(A) sum(A) ans p = sorted(p, reverse=True, key=lambda x: x[1]) sorted(p, reverse=True, key=lambda x: x[1]) p j = 0 0 j j = i i j minv = min(A) min(A) minv p = [ list(map(int, input().split())) for i in range(M) ] [ list(map(int, input().split())) for i in range(M) ] p i = 0 0 i maxv = max(A) max(A) maxv ans = ans - A[i] + x[1] ans - A[i] + x[1] ans cnt = 0 0 cnt
N, M = map(int,input().split())
A = sorted(list(map(int, input().split())))
p = [ list(map(int, input().split())) for i in range(M) ]
p = sorted(p, reverse=True, key=lambda x: x[1])

maxv = max(A)
minv = min(A)
ans = sum(A)

if p[0][1] < minv:
    print(ans)
else:
    cnt = 0
    j = 0
    i = 0
    for x in p:
        while(i < min(j + x[0], N)):
            if x[1] > A[i]:
                ans = ans - A[i] + x[1]
                i = i+1
            else:
                break
        else:
            j = i
            if j >= N:
                break
            continue
        break
    print(ans)