from collections import defaultdict

def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans)







if __name__ == '__main__':
    main() from collections import defaultdict def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans) main N,M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M d = defaultdict(lambda: 0) d defaultdict(lambda: 0) defaultdict lambda: 0 0 A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 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 d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True) d_sorted sorted(d.items(), key=lambda x:x[0], reverse=True) sorted d.items() d.items d items key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True ans = 0 ans 0 for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



     i range(len(d_sorted)) range len(d_sorted) len d_sorted ans += d_sorted[i][0] * min(d_sorted[i][1],N) ans d_sorted[i][0] * min(d_sorted[i][1],N) d_sorted[i][0] [i] d_sorted i 0 min(d_sorted[i][1],N) min d_sorted[i][1] [i] d_sorted i 1 N N -= min(d_sorted[i][1],N) N min(d_sorted[i][1],N) min d_sorted[i][1] [i] d_sorted i 1 N if N == 0:
            break



     N == 0 N 0 break print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans) def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans) main
from collections import defaultdict

def main():
    N,M = map(int, input().split())
    d = defaultdict(lambda: 0)
    A = list(map(int, input().split()))

    for a in A:
        d[a]+=1

    for _ in range(M):
        B,C = map(int, input().split())
        d[C]+=B

    d_sorted = sorted(d.items(), key=lambda x:x[0], reverse=True)
    ans = 0

    for i in range(len(d_sorted)):
        ans += d_sorted[i][0] * min(d_sorted[i][1],N)
        N -= min(d_sorted[i][1],N)
        if N == 0:
            break



    print(ans)







if __name__ == '__main__':
    main()