def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans)



if __name__ == '__main__':
    main() def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans) main import sys sys def input(): return sys.stdin.readline().rstrip()
    
     input 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 from collections import Counter as cc a = cc(a) a cc(a) cc a (key, a[key]) for key in a for key in a key a for key in a (key, a[key]) key a[key] a key q = [(key, a[key]) for key in a] q [(key, a[key]) for key in a] for i in range(m):
        b, c = map(int, input().split())
        q.append((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 q.append((c,b)) q.append q append (c,b) c b q.sort(reverse=True) q.sort q sort reverse=True reverse True acc = 0 acc 0 ans = 0 ans 0 for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
     num cnt q if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
         acc + cnt >= n acc + cnt acc cnt n cnt = n-acc cnt n-acc n acc ans += num*cnt ans num*cnt num cnt break acc += cnt acc cnt ans += num*cnt ans num*cnt num cnt print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans) def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans) main
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = [(key, a[key]) for key in a]
    for i in range(m):
        b, c = map(int, input().split())
        q.append((c,b))
    q.sort(reverse=True)
    acc = 0
    ans = 0
    for num, cnt in q:
        if acc + cnt >= n:
            cnt = n-acc
            ans += num*cnt
            break
        acc += cnt
        ans += num*cnt
    print(ans)



if __name__ == '__main__':
    main()