n,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for _ in range(m)]
a.sort()
b = sorted(b,key = lambda  x: x[1],reverse=True)
d = []
j = 0
while (n<=len(a) or j<m) :
    C = b[j][1]
    B = b[j][0]
    for i in range(B) :
        d.append(C)
    j += 1
    if j>=m or len(d) > len(a) :
        break

for i in range(min(len(d),len(a))) :
    if a[i] < d[i] :
        a[i] = d[i]

print(sum(a)) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] [int(i) for i in input().split()] for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [int(i) for i in input().split()] b = [[int(i) for i in input().split()] for _ in range(m)] b [[int(i) for i in input().split()] for _ in range(m)] a.sort() a.sort a sort b = sorted(b,key = lambda  x: x[1],reverse=True) b sorted(b,key = lambda  x: x[1],reverse=True) sorted b key = lambda  x: x[1] key lambda  x: x[1] x[1] x 1 x reverse=True reverse True d = [] d [] j = 0 j 0 while (n<=len(a) or j<m) :
    C = b[j][1]
    B = b[j][0]
    for i in range(B) :
        d.append(C)
    j += 1
    if j>=m or len(d) > len(a) :
        break n<=len(a) or j<m n<=len(a) n len(a) len a j<m j m C = b[j][1] C b[j][1] [j] b j 1 B = b[j][0] B b[j][0] [j] b j 0 for i in range(B) :
        d.append(C)
     i range(B) range B d.append(C) d.append d append C j += 1 j 1 if j>=m or len(d) > len(a) :
        break j>=m or len(d) > len(a) j>=m j m len(d) > len(a) len(d) len d len(a) len a break for i in range(min(len(d),len(a))) :
    if a[i] < d[i] :
        a[i] = d[i] i range(min(len(d),len(a))) range min(len(d),len(a)) min len(d) len d len(a) len a if a[i] < d[i] :
        a[i] = d[i] a[i] < d[i] a[i] a i d[i] d i a[i] = d[i] a[i] a i d[i] d i print(sum(a)) print sum(a) sum a C = b[j][1] b[j][1] C d = [] [] d j = 0 0 j b = sorted(b,key = lambda  x: x[1],reverse=True) sorted(b,key = lambda  x: x[1],reverse=True) b m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n a = [int(i) for i in input().split()] [int(i) for i in input().split()] a j += 1 1 j b = [[int(i) for i in input().split()] for _ in range(m)] [[int(i) for i in input().split()] for _ in range(m)] b B = b[j][0] b[j][0] B
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for _ in range(m)]
a.sort()
b = sorted(b,key = lambda  x: x[1],reverse=True)
d = []
j = 0
while (n<=len(a) or j<m) :
    C = b[j][1]
    B = b[j][0]
    for i in range(B) :
        d.append(C)
    j += 1
    if j>=m or len(d) > len(a) :
        break

for i in range(min(len(d),len(a))) :
    if a[i] < d[i] :
        a[i] = d[i]

print(sum(a))