def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    h = {}
    for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
    for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
    ans = 0
    for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
    print(ans)


if __name__ == "__main__":
    main() def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    h = {}
    for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
    for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
    ans = 0
    for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
    print(ans) main 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 h = {} h {} for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[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 if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
     c not in h.keys() c h.keys() h.keys h keys h[c] = b h[c] h c b h[c]+=b h[c] h c b for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
     i range(n) range n if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
     a[i] not in h.keys() a[i] a i h.keys() h.keys h keys h[a[i]]=1 h[a[i]] h a[i] a i 1 h[a[i]]+=1 h[a[i]] h a[i] a i 1 ans = 0 ans 0 for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
     k sorted(h.keys(),reverse=True) sorted h.keys() h.keys h keys reverse=True reverse True if n<h[k]:
            ans += n*k
            break
         n<h[k] n h[k] h k ans += n*k ans n*k n k break ans += h[k]*k ans h[k]*k h[k] h k k n = n-h[k] n n-h[k] n h[k] h k print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    h = {}
    for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
    for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
    ans = 0
    for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
    print(ans) def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    h = {}
    for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
    for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
    ans = 0
    for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
    print(ans) main
def main():
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    h = {}
    for i in range(m):
        b,c = map(int,input().split())
        if c not in h.keys():
            h[c] = b
        else:
            h[c]+=b
    for i in range(n):
        if a[i] not in h.keys():
            h[a[i]]=1
        else:
            h[a[i]]+=1
    ans = 0
    for k in sorted(h.keys(),reverse=True):
        if n<h[k]:
            ans += n*k
            break
        ans += h[k]*k
        n = n-h[k]
    print(ans)


if __name__ == "__main__":
    main()
