from collections import Counter


def main():
    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in a.items():
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans)


if __name__ == '__main__':
    main()
 from collections import Counter def main():
    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in a.items():
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans) main n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = Counter(list(map(int, input().split()))) a Counter(list(map(int, input().split()))) Counter list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cards = [] cards [] for i, v in a.items():
        cards.append([i, v])
     i v a.items() a.items a items cards.append([i, v]) cards.append cards append [i, v] i v for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
     _ range(m) range m cards.append(list(map(int, input().split()))[::-1]) cards.append cards append list(map(int, input().split()))[::-1] (map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ::-1 -1 cards.sort(key=lambda x: x[0], reverse=True) cards.sort cards sort 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, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
     i v cards ans += i * min(v, n) ans i * min(v, n) i min(v, n) min v n n -= min(v, n) n min(v, n) min v n print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in a.items():
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans) def main():
    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in a.items():
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans) main
from collections import Counter


def main():
    n, m = map(int, input().split())
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in a.items():
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans)


if __name__ == '__main__':
    main()

