import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    A = read_ints()
    BC: List[List[int]] = []
    for _ in range(M):
        BC.append(read_ints())
    A.sort()
    BC.sort(key=lambda pair: pair[1])
    chosen = 0
    answer = 0

    def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

    while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
    return answer


if __name__ == '__main__':
    print(solve()) import math math from typing import List, Any def read_int() -> int:
    return int(input().strip()) read_int return int(input().strip()) int(input().strip()) int input().strip() ().strip () input strip def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) read_ints return list(map(int, input().strip().split(' '))) list(map(int, input().strip().split(' '))) list map(int, input().strip().split(' ')) map int input().strip().split(' ') ().strip().split ().strip() ().strip () input strip split ' ' def solve() -> Any:
    N, M = read_ints()
    A = read_ints()
    BC: List[List[int]] = []
    for _ in range(M):
        BC.append(read_ints())
    A.sort()
    BC.sort(key=lambda pair: pair[1])
    chosen = 0
    answer = 0

    def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

    while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
    return answer solve N, M = read_ints() N read_ints() read_ints M A = read_ints() A read_ints() read_ints BC: List[List[int]] = [] BC [] for _ in range(M):
        BC.append(read_ints())
     _ range(M) range M BC.append(read_ints()) BC.append BC append read_ints() read_ints A.sort() A.sort A sort BC.sort(key=lambda pair: pair[1]) BC.sort BC sort key=lambda pair: pair[1] key lambda pair: pair[1] pair[1] pair 1 pair chosen = 0 chosen 0 answer = 0 answer 0 def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

     pop_bc nonlocal answer bc = BC.pop() bc BC.pop() BC.pop BC pop bc[0] -= 1 bc[0] bc 0 1 if bc[0] > 0:
            BC.append(bc)
         bc[0] > 0 bc[0] bc 0 0 BC.append(bc) BC.append BC append bc return bc[1] bc[1] bc 1 while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
     chosen < N chosen N if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
         A and BC A BC if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
         A[-1] > BC[-1][1] A[-1] A -1 BC[-1][1] [-1] BC -1 1 answer += A.pop() answer A.pop() A.pop A pop answer += pop_bc() answer pop_bc() pop_bc elif A:
            answer += A.pop()
         A answer += A.pop() answer A.pop() A.pop A pop answer += pop_bc() answer pop_bc() pop_bc chosen += 1 chosen 1 return answer answer if __name__ == '__main__':
    print(solve()) __name__ == '__main__' __name__ '__main__' print(solve()) print solve() solve def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' '))) read_ints def solve() -> Any:
    N, M = read_ints()
    A = read_ints()
    BC: List[List[int]] = []
    for _ in range(M):
        BC.append(read_ints())
    A.sort()
    BC.sort(key=lambda pair: pair[1])
    chosen = 0
    answer = 0

    def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

    while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
    return answer def solve() -> Any:
    N, M = read_ints()
    A = read_ints()
    BC: List[List[int]] = []
    for _ in range(M):
        BC.append(read_ints())
    A.sort()
    BC.sort(key=lambda pair: pair[1])
    chosen = 0
    answer = 0

    def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

    while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
    return answer solve def read_int() -> int:
    return int(input().strip()) def read_int() -> int:
    return int(input().strip()) read_int
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N, M = read_ints()
    A = read_ints()
    BC: List[List[int]] = []
    for _ in range(M):
        BC.append(read_ints())
    A.sort()
    BC.sort(key=lambda pair: pair[1])
    chosen = 0
    answer = 0

    def pop_bc():
        nonlocal answer
        bc = BC.pop()
        bc[0] -= 1
        if bc[0] > 0:
            BC.append(bc)
        return bc[1]

    while chosen < N:
        if A and BC:
            if A[-1] > BC[-1][1]:
                answer += A.pop()
            else:
                answer += pop_bc()
        elif A:
            answer += A.pop()
        else:
            answer += pop_bc()
        chosen += 1
    return answer


if __name__ == '__main__':
    print(solve())
