def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans)


if __name__ == '__main__':
    main() def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans) main from collections import Counter n, m, *abc = map(int, open(0).read().split()) n map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *abc abc a = Counter(abc[:n]) a Counter(abc[:n]) Counter abc[:n] abc :n n bc = abc[n:] bc abc[n:] abc n: n for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

     i j zip(*[iter(bc)] * 2) zip *[iter(bc)] * 2 [iter(bc)] * 2 [iter(bc)] iter(bc) iter bc 2 a[j] += i a[j] a j i cnt = n cnt n ans = 0 ans 0 keys = sorted(list(a.keys()), reverse=True) keys sorted(list(a.keys()), reverse=True) sorted list(a.keys()) list a.keys() a.keys a keys reverse=True reverse True for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

     k keys m = a[k] m a[k] a k if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

     m <= cnt m cnt ans += k * m ans k * m k m cnt -= m cnt m ans += k * cnt ans k * cnt k cnt break print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans) def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans) main
def main():
    from collections import Counter
    n, m, *abc = map(int, open(0).read().split())
    a = Counter(abc[:n])
    bc = abc[n:]
    for i, j in zip(*[iter(bc)] * 2):
        a[j] += i

    cnt = n
    ans = 0
    keys = sorted(list(a.keys()), reverse=True)
    
    for k in keys:
        m = a[k]
        if m <= cnt:
            ans += k * m
            cnt -= m
        else:
            ans += k * cnt
            break

    print(ans)


if __name__ == '__main__':
    main()
