import collections


def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    A.sort()
    bc.sort(key=lambda x: x[1], reverse=True)
    i, j = 0, 0

    while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
    print(sum(A))


if __name__ == '__main__':
    main() import collections collections def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    A.sort()
    bc.sort(key=lambda x: x[1], reverse=True)
    i, j = 0, 0

    while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
    print(sum(A)) 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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [list(map(int, input().split())) for _ in range(m)] bc [list(map(int, input().split())) for _ in range(m)] A.sort() A.sort A sort 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 i, j = 0, 0 i 0 j 0 while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
     i < n and j < m i < n i n j < m j m if A[i] >= bc[j][1]:
            break
         A[i] >= bc[j][1] A[i] A i bc[j][1] [j] bc j 1 break A[i] = bc[j][1] A[i] A i bc[j][1] [j] bc j 1 i += 1 i 1 bc[j][0] -= 1 bc[j][0] [j] bc j 0 1 if bc[j][0] == 0:
            j += 1
     bc[j][0] == 0 bc[j][0] [j] bc j 0 0 j += 1 j 1 print(sum(A)) print sum(A) sum A if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    A.sort()
    bc.sort(key=lambda x: x[1], reverse=True)
    i, j = 0, 0

    while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
    print(sum(A)) def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    A.sort()
    bc.sort(key=lambda x: x[1], reverse=True)
    i, j = 0, 0

    while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
    print(sum(A)) main
import collections


def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    A.sort()
    bc.sort(key=lambda x: x[1], reverse=True)
    i, j = 0, 0

    while i < n and j < m:
        if A[i] >= bc[j][1]:
            break
        A[i] = bc[j][1]
        i += 1
        bc[j][0] -= 1
        if bc[j][0] == 0:
            j += 1
    print(sum(A))


if __name__ == '__main__':
    main()
