def main():
    from collections import defaultdict
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = map(int, input().split())

    ctr = defaultdict(int)
    for x in A:
        ctr[x] += 1

    for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

    rest = N
    total = 0
    for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

    print(total)


if __name__ == '__main__':
    main() def main():
    from collections import defaultdict
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = map(int, input().split())

    ctr = defaultdict(int)
    for x in A:
        ctr[x] += 1

    for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

    rest = N
    total = 0
    for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

    print(total) main from collections import defaultdict from operator import itemgetter import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = map(int, input().split()) A map(int, input().split()) map int input().split() ().split () input split ctr = defaultdict(int) ctr defaultdict(int) defaultdict int for x in A:
        ctr[x] += 1

     x A ctr[x] += 1 ctr[x] ctr x 1 for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

     _ range(M) range M num_of_cards, int_written_on_cards = map(int, input().split()) num_of_cards map(int, input().split()) map int input().split() ().split () input split int_written_on_cards ctr[int_written_on_cards] += num_of_cards ctr[int_written_on_cards] ctr int_written_on_cards num_of_cards rest = N rest N total = 0 total 0 for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

     int_written_on_cards num_of_cards sorted(ctr.items(), key=itemgetter(0), reverse=True) sorted ctr.items() ctr.items ctr items key=itemgetter(0) key itemgetter(0) itemgetter 0 reverse=True reverse True take = min(rest, num_of_cards) take min(rest, num_of_cards) min rest num_of_cards total += int_written_on_cards * take total int_written_on_cards * take int_written_on_cards take rest -= take rest take if rest == 0:
            break

     rest == 0 rest 0 break print(total) print total if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from collections import defaultdict
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = map(int, input().split())

    ctr = defaultdict(int)
    for x in A:
        ctr[x] += 1

    for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

    rest = N
    total = 0
    for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

    print(total) def main():
    from collections import defaultdict
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = map(int, input().split())

    ctr = defaultdict(int)
    for x in A:
        ctr[x] += 1

    for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

    rest = N
    total = 0
    for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

    print(total) main
def main():
    from collections import defaultdict
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = map(int, input().split())

    ctr = defaultdict(int)
    for x in A:
        ctr[x] += 1

    for _ in range(M):
        num_of_cards, int_written_on_cards = map(int, input().split())
        ctr[int_written_on_cards] += num_of_cards

    rest = N
    total = 0
    for int_written_on_cards, num_of_cards in sorted(ctr.items(), key=itemgetter(0), reverse=True):
        take = min(rest, num_of_cards)

        total += int_written_on_cards * take
        rest -= take

        if rest == 0:
            break

    print(total)


if __name__ == '__main__':
    main()
