from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = Counter(a)

for i in range(m):
    b, c = map(int, input().split())
    d[c] += b
key = list(d.keys())
key.sort(reverse = True)

ans = 0
for k in key:
    if n <= d[k]:
        ans += k*n
        break
    else:
        ans += k*d[k]
        n -= d[k]

print(ans) from collections import Counter 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 d = Counter(a) d Counter(a) Counter a for i in range(m):
    b, c = map(int, input().split())
    d[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[c] += b d[c] d c b key = list(d.keys()) key list(d.keys()) list d.keys() d.keys d keys key.sort(reverse = True) key.sort key sort reverse = True reverse True ans = 0 ans 0 for k in key:
    if n <= d[k]:
        ans += k*n
        break
    else:
        ans += k*d[k]
        n -= d[k] k key if n <= d[k]:
        ans += k*n
        break
    else:
        ans += k*d[k]
        n -= d[k] n <= d[k] n d[k] d k ans += k*n ans k*n k n break ans += k*d[k] ans k*d[k] k d[k] d k n -= d[k] n d[k] d k print(ans) print ans ans += k*d[k] k*d[k] ans m = map(int, input().split()) map(int, input().split()) m a = list(map(int, input().split())) list(map(int, input().split())) a c = map(int, input().split()) map(int, input().split()) c n -= d[k] d[k] n d = Counter(a) Counter(a) d ans += k*n k*n ans n, m = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b key = list(d.keys()) list(d.keys()) key ans = 0 0 ans
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = Counter(a)

for i in range(m):
    b, c = map(int, input().split())
    d[c] += b
key = list(d.keys())
key.sort(reverse = True)

ans = 0
for k in key:
    if n <= d[k]:
        ans += k*n
        break
    else:
        ans += k*d[k]
        n -= d[k]

print(ans)