n, m = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
for i in range(m):
    bb, cc = map(int,input().split())
    b.append(bb)
    c.append(cc)

pairs = []
for i in range(n):
    pairs.append( (a[i], 1) )
for i in range(m):
    pairs.append( (c[i], b[i]) )

pairs.sort(reverse = True)

idx = 0
res = 0
for i in range(n):
    if pairs[idx][1]== 0:
        idx += 1
    p = list(pairs[idx])        
    res += p[0]
    p[1] -= 1
    pairs[idx] = tuple(p)
    
print(res)
    
     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 b = [] b [] c = [] c [] for i in range(m):
    bb, cc = map(int,input().split())
    b.append(bb)
    c.append(cc) i range(m) range m bb, cc = map(int,input().split()) bb map(int,input().split()) map int input().split() ().split () input split cc b.append(bb) b.append b append bb c.append(cc) c.append c append cc pairs = [] pairs [] for i in range(n):
    pairs.append( (a[i], 1) ) i range(n) range n pairs.append( (a[i], 1) ) pairs.append pairs append (a[i], 1) a[i] a i 1 for i in range(m):
    pairs.append( (c[i], b[i]) ) i range(m) range m pairs.append( (c[i], b[i]) ) pairs.append pairs append (c[i], b[i]) c[i] c i b[i] b i pairs.sort(reverse = True) pairs.sort pairs sort reverse = True reverse True idx = 0 idx 0 res = 0 res 0 for i in range(n):
    if pairs[idx][1]== 0:
        idx += 1
    p = list(pairs[idx])        
    res += p[0]
    p[1] -= 1
    pairs[idx] = tuple(p)
     i range(n) range n if pairs[idx][1]== 0:
        idx += 1
     pairs[idx][1]== 0 pairs[idx][1] [idx] pairs idx 1 0 idx += 1 idx 1 p = list(pairs[idx]) p list(pairs[idx]) list pairs[idx] pairs idx res += p[0] res p[0] p 0 p[1] -= 1 p[1] p 1 1 pairs[idx] = tuple(p) pairs[idx] pairs idx tuple(p) tuple p print(res) print res cc = map(int,input().split()) map(int,input().split()) cc m = map(int,input().split()) map(int,input().split()) m c = [] [] c pairs = [] [] pairs a = list(map(int,input().split())) list(map(int,input().split())) a res += p[0] p[0] res idx = 0 0 idx idx += 1 1 idx bb, cc = map(int,input().split()) map(int,input().split()) bb p = list(pairs[idx]) list(pairs[idx]) p b = [] [] b n, m = map(int,input().split()) map(int,input().split()) n res = 0 0 res
n, m = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
for i in range(m):
    bb, cc = map(int,input().split())
    b.append(bb)
    c.append(cc)

pairs = []
for i in range(n):
    pairs.append( (a[i], 1) )
for i in range(m):
    pairs.append( (c[i], b[i]) )

pairs.sort(reverse = True)

idx = 0
res = 0
for i in range(n):
    if pairs[idx][1]== 0:
        idx += 1
    p = list(pairs[idx])        
    res += p[0]
    p[1] -= 1
    pairs[idx] = tuple(p)
    
print(res)
    
    
