N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
b_list = []
c_list = []
for _ in range(M):
    b, c, = list(map(int, input().split()))
    b_list.append(b)
    c_list.append(c)

data = dict()
for a in A:
    if a in data:
        data[a] += 1
    else:
        data[a] = 1

for i in range(M):
    if c_list[i] in data:
        data[c_list[i]] += b_list[i]
    else:
        data[c_list[i]] = b_list[i]

key = list(data.keys())
key.sort(reverse=True)
num = 0
ind = 0
ans = 0
while True:
    if num + data[key[ind]] <= N:
        ans += data[key[ind]]*key[ind]
        num += data[key[ind]]
    else:
        ans += (N - num)*key[ind]
        break
    ind += 1
print(ans) N, M = list(map(int, input().split())) N list(map(int, input().split())) list 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_list = [] b_list [] c_list = [] c_list [] for _ in range(M):
    b, c, = list(map(int, input().split()))
    b_list.append(b)
    c_list.append(c) _ range(M) range M b, c, = list(map(int, input().split())) b list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c b_list.append(b) b_list.append b_list append b c_list.append(c) c_list.append c_list append c data = dict() data dict() dict for a in A:
    if a in data:
        data[a] += 1
    else:
        data[a] = 1 a A if a in data:
        data[a] += 1
    else:
        data[a] = 1 a in data a data data[a] += 1 data[a] data a 1 data[a] = 1 data[a] data a 1 for i in range(M):
    if c_list[i] in data:
        data[c_list[i]] += b_list[i]
    else:
        data[c_list[i]] = b_list[i] i range(M) range M if c_list[i] in data:
        data[c_list[i]] += b_list[i]
    else:
        data[c_list[i]] = b_list[i] c_list[i] in data c_list[i] c_list i data data[c_list[i]] += b_list[i] data[c_list[i]] data c_list[i] c_list i b_list[i] b_list i data[c_list[i]] = b_list[i] data[c_list[i]] data c_list[i] c_list i b_list[i] b_list i key = list(data.keys()) key list(data.keys()) list data.keys() data.keys data keys key.sort(reverse=True) key.sort key sort reverse=True reverse True num = 0 num 0 ind = 0 ind 0 ans = 0 ans 0 while True:
    if num + data[key[ind]] <= N:
        ans += data[key[ind]]*key[ind]
        num += data[key[ind]]
    else:
        ans += (N - num)*key[ind]
        break
    ind += 1 True if num + data[key[ind]] <= N:
        ans += data[key[ind]]*key[ind]
        num += data[key[ind]]
    else:
        ans += (N - num)*key[ind]
        break
     num + data[key[ind]] <= N num + data[key[ind]] num data[key[ind]] data key[ind] key ind N ans += data[key[ind]]*key[ind] ans data[key[ind]]*key[ind] data[key[ind]] data key[ind] key ind key[ind] key ind num += data[key[ind]] num data[key[ind]] data key[ind] key ind ans += (N - num)*key[ind] ans (N - num)*key[ind] N - num N num key[ind] key ind break ind += 1 ind 1 print(ans) print ans num += data[key[ind]] data[key[ind]] num c, = list(map(int, input().split())) list(map(int, input().split())) c N, M = list(map(int, input().split())) list(map(int, input().split())) N M = list(map(int, input().split())) list(map(int, input().split())) M ind = 0 0 ind ans += data[key[ind]]*key[ind] data[key[ind]]*key[ind] ans ans = 0 0 ans b, c, = list(map(int, input().split())) list(map(int, input().split())) b c_list = [] [] c_list ans += (N - num)*key[ind] (N - num)*key[ind] ans A = list(map(int, input().split())) list(map(int, input().split())) A key = list(data.keys()) list(data.keys()) key b_list = [] [] b_list ind += 1 1 ind data = dict() dict() data num = 0 0 num
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
b_list = []
c_list = []
for _ in range(M):
    b, c, = list(map(int, input().split()))
    b_list.append(b)
    c_list.append(c)

data = dict()
for a in A:
    if a in data:
        data[a] += 1
    else:
        data[a] = 1

for i in range(M):
    if c_list[i] in data:
        data[c_list[i]] += b_list[i]
    else:
        data[c_list[i]] = b_list[i]

key = list(data.keys())
key.sort(reverse=True)
num = 0
ind = 0
ans = 0
while True:
    if num + data[key[ind]] <= N:
        ans += data[key[ind]]*key[ind]
        num += data[key[ind]]
    else:
        ans += (N - num)*key[ind]
        break
    ind += 1
print(ans)
