from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main() from operator import itemgetter def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
     main N,M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M [1,int(x)] for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() [1,int(x)] 1 int(x) int x A = [[1,int(x)] for x in input().split()] A [[1,int(x)] for x in input().split()] for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
     _ range(M) range M b,c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c A.append([b,c]) A.append A append [b,c] b c A.sort(key=itemgetter(1)) A.sort A sort key=itemgetter(1) key itemgetter(1) itemgetter 1 A.reverse() A.reverse A reverse n=0 n 0 s=0 s 0 for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
     a A n+=a[0] n a[0] a 0 if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
     n<=N n N s+=a[1]*a[0] s a[1]*a[0] a[1] a 1 a[0] a 0 elif n>N:
            d=a[0]
            e=a[1]
            break
     n>N n N d=a[0] d a[0] a 0 e=a[1] e a[1] a 1 break s+=(N-n+d)*e s (N-n+d)*e N-n+d N-n N n d e print(s) print s main() main def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
     def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
     main
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()