from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans)


if __name__ == '__main__':
    main() from collections import defaultdict import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans) main 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 = defaultdict(int) d defaultdict(int) defaultdict int for a in A:
        d[a] += 1
     a A d[a] += 1 d[a] d a 1 for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

     _ 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 ans = 0 ans 0 total_freq = 0 total_freq 0 for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
     v freq sorted(d.items(), reverse=True) sorted d.items() d.items d items reverse=True reverse True if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
     total_freq + freq <= N total_freq + freq total_freq freq N ans += v * freq ans v * freq v freq total_freq += freq total_freq freq ans += v * (N - total_freq) ans v * (N - total_freq) v N - total_freq N total_freq break print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input = sys.stdin.readline sys.stdin.readline input def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans) def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans) main
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    for _ in range(M):
        B, C = map(int, input().split())
        d[C] += B

    ans = 0
    total_freq = 0
    for v, freq in sorted(d.items(), reverse=True):
        if total_freq + freq <= N:
            ans += v * freq
            total_freq += freq
        else:
            ans += v * (N - total_freq)
            break
    print(ans)


if __name__ == '__main__':
    main()
