n,m = list(map(int,input().split()))

a = list(map(int,input().split()))

p = [[aa,1] for aa in a]

for _ in range(m):

  b = list(map(int,input().split()))

  b.reverse()

  p.append(b)

p.sort()

p.reverse()

rest = n

score = 0

for pp in p:

  use = min(pp[1],rest)

  rest -= use

  score += pp[0] * use

print(score)
n,m = list(map(int,input().split()))

a = list(map(int,input().split()))

p = [[aa,1] for aa in a]

for _ in range(m):

  b = list(map(int,input().split()))

  b.reverse()

  p.append(b)

p.sort()

p.reverse()

rest = n

score = 0

for pp in p:

  use = min(pp[1],rest)

  rest -= use

  score += pp[0] * use

  if rest==0: break

print(score)
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
p = [[aa, 1] for aa in a]
for _ in range(m):
    b = list(map(int, input().split()))
    b.reverse()
    p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for pp in p:
    use = min(pp[1], rest)
    rest -= use
    score += pp[0] * use
print(score)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
p = [[aa, 1] for aa in a]
for _ in range(m):
    b = list(map(int, input().split()))
    b.reverse()
    p.append(b)
p.sort()
p.reverse()
rest = n
score = 0
for pp in p:
    use = min(pp[1], rest)
    rest -= use
    score += pp[0] * use
    if rest == 0:
        break
print(score)

+    if rest == 0: +        break