n, m = map(int, input().split())
l = [(a, 1) for a in list(map(int, input().split()))]
for i in range(m):
    b, c = map(int, input().split())
    l.append((c, b))
l = sorted(l)[::-1]
ans = 0

for i, j in l:
    if j < n:
        ans += i*j
        n -= j
    else:
        ans += n*i
        break

print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m (a, 1) for a in list(map(int, input().split())) for a in list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for a in list(map(int, input().split())) (a, 1) a 1 l = [(a, 1) for a in list(map(int, input().split()))] l [(a, 1) for a in list(map(int, input().split()))] for i in range(m):
    b, c = map(int, input().split())
    l.append((c, b)) i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c l.append((c, b)) l.append l append (c, b) c b l = sorted(l)[::-1] l sorted(l)[::-1] (l) sorted l ::-1 -1 ans = 0 ans 0 for i, j in l:
    if j < n:
        ans += i*j
        n -= j
    else:
        ans += n*i
        break i j l if j < n:
        ans += i*j
        n -= j
    else:
        ans += n*i
        break j < n j n ans += i*j ans i*j i j n -= j n j ans += n*i ans n*i n i break print(ans) print ans l = [(a, 1) for a in list(map(int, input().split()))] [(a, 1) for a in list(map(int, input().split()))] l ans += i*j i*j ans l = sorted(l)[::-1] sorted(l)[::-1] l m = map(int, input().split()) map(int, input().split()) m c = map(int, input().split()) map(int, input().split()) c ans += n*i n*i ans n, m = map(int, input().split()) map(int, input().split()) n ans = 0 0 ans b, c = map(int, input().split()) map(int, input().split()) b n -= j j n
n, m = map(int, input().split())
l = [(a, 1) for a in list(map(int, input().split()))]
for i in range(m):
    b, c = map(int, input().split())
    l.append((c, b))
l = sorted(l)[::-1]
ans = 0

for i, j in l:
    if j < n:
        ans += i*j
        n -= j
    else:
        ans += n*i
        break

print(ans)