N, M = map(int, input().split())
A = list(map(int, input().split()))
D = [(A[i], 1) for i in range(N)]

for i in range(M):
  B, C = (map(int, input().split()))
  D.append((C, B))
  
D.sort()
D.reverse()

ans, left = 0, N
for (i, j) in D:
    use = min(j, left)
    ans += use * i
    left -= use
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split (A[i], 1) for i in range(N) for i in range(N) i range(N) range N for i in range(N) (A[i], 1) A[i] A i 1 D = [(A[i], 1) for i in range(N)] D [(A[i], 1) for i in range(N)] for i in range(M):
  B, C = (map(int, input().split()))
  D.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 D.append((C, B)) D.append D append (C, B) C B D.sort() D.sort D sort D.reverse() D.reverse D reverse ans, left = 0, N ans 0 left N for (i, j) in D:
    use = min(j, left)
    ans += use * i
    left -= use (i, j) i j D use = min(j, left) use min(j, left) min j left ans += use * i ans use * i use i left -= use left use print(ans) print ans C = (map(int, input().split())) map(int, input().split()) C A = list(map(int, input().split())) list(map(int, input().split())) A ans += use * i use * i ans N, M = map(int, input().split()) map(int, input().split()) N B, C = (map(int, input().split())) map(int, input().split()) B use = min(j, left) min(j, left) use ans, left = 0, N 0 ans D = [(A[i], 1) for i in range(N)] [(A[i], 1) for i in range(N)] D left = 0, N N left M = map(int, input().split()) map(int, input().split()) M left -= use use left
N, M = map(int, input().split())
A = list(map(int, input().split()))
D = [(A[i], 1) for i in range(N)]

for i in range(M):
  B, C = (map(int, input().split()))
  D.append((C, B))
  
D.sort()
D.reverse()

ans, left = 0, N
for (i, j) in D:
    use = min(j, left)
    ans += use * i
    left -= use
print(ans)