import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    BC = [()] * M
    for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

    BC.sort(key=lambda x: x[1], reverse=True)

    am = []
    for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

    A += am
    A.sort(reverse=True)
    ans = sum(A[:N])
    print(ans)


if __name__ == '__main__':
    solve() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    BC = [()] * M
    for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

    BC.sort(key=lambda x: x[1], reverse=True)

    am = []
    for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

    A += am
    A.sort(reverse=True)
    ans = sum(A[:N])
    print(ans) solve 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 BC = [()] * M BC [()] * M [()] () M for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

     i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c BC[i] = (b, c) BC[i] BC i (b, c) b c BC.sort(key=lambda x: x[1], reverse=True) BC.sort BC sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True am = [] am [] for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

     bc BC b, c = bc[0], bc[1] b bc[0] bc 0 c bc[1] bc 1 if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

         len(am) + b <= N len(am) + b len(am) len am b N am += [c] * b am [c] * b [c] c b am += [c] * (N - len(am)) am [c] * (N - len(am)) [c] c N - len(am) N len(am) len am if len(am) == N:
            break

     len(am) == N len(am) len am N break A += am A am A.sort(reverse=True) A.sort A sort reverse=True reverse True ans = sum(A[:N]) ans sum(A[:N]) sum A[:N] A :N N print(ans) print ans if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    BC = [()] * M
    for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

    BC.sort(key=lambda x: x[1], reverse=True)

    am = []
    for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

    A += am
    A.sort(reverse=True)
    ans = sum(A[:N])
    print(ans) def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    BC = [()] * M
    for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

    BC.sort(key=lambda x: x[1], reverse=True)

    am = []
    for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

    A += am
    A.sort(reverse=True)
    ans = sum(A[:N])
    print(ans) solve
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    BC = [()] * M
    for i in range(M):
        b, c = map(int, input().split())
        BC[i] = (b, c)

    BC.sort(key=lambda x: x[1], reverse=True)

    am = []
    for bc in BC:
        b, c = bc[0], bc[1]
        if len(am) + b <= N:
            am += [c] * b
        else:
            am += [c] * (N - len(am))

        if len(am) == N:
            break

    A += am
    A.sort(reverse=True)
    ans = sum(A[:N])
    print(ans)


if __name__ == '__main__':
    solve()
