from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
aa = Counter(LIST())
aa = sorted(aa.items(), key=itemgetter(0))
a = [[aa[i][1], aa[i][0]] for i in range(len(aa))]
b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True)

ans = 0
i = j = 0
while i < len(b) and j < len(a) and b[i][1] > a[j][1]:
    if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1
reg = j
if reg < len(a):
    for i in range(j, len(a)):
        ans += a[i][0]*a[i][1]
print(ans) from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heappop,heappush from copy import deepcopy from time import time import string string import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 def input() : return sys.stdin.readline().strip() input def INT()   : return int(input()) INT def MAP()   : return map(int,input().split()) MAP def LIST()  : return list(MAP()) LIST n, m = MAP() n MAP() MAP m aa = Counter(LIST()) aa Counter(LIST()) Counter LIST() LIST aa = sorted(aa.items(), key=itemgetter(0)) aa sorted(aa.items(), key=itemgetter(0)) sorted aa.items() aa.items aa items key=itemgetter(0) key itemgetter(0) itemgetter 0 [aa[i][1], aa[i][0]] for i in range(len(aa)) for i in range(len(aa)) i range(len(aa)) range len(aa) len aa for i in range(len(aa)) [aa[i][1], aa[i][0]] aa[i][1] [i] aa i 1 aa[i][0] [i] aa i 0 a = [[aa[i][1], aa[i][0]] for i in range(len(aa))] a [[aa[i][1], aa[i][0]] for i in range(len(aa))] LIST() for i in range(m) for i in range(m) i range(m) range m for i in range(m) LIST() LIST b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True) b sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True) sorted [LIST() for i in range(m)] key=itemgetter(1) key itemgetter(1) itemgetter 1 reverse=True reverse True ans = 0 ans 0 i = j = 0 i 0 = j = 0 j 0 while i < len(b) and j < len(a) and b[i][1] > a[j][1]:
    if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1 i < len(b) and j < len(a) and b[i][1] > a[j][1] i < len(b) and j < len(a) i < len(b) i len(b) len b j < len(a) j len(a) len a b[i][1] > a[j][1] b[i][1] [i] b i 1 a[j][1] [j] a j 1 if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1 b[i][0] >= a[j][0] b[i][0] [i] b i 0 a[j][0] [j] a j 0 ans += b[i][1]*a[j][0] ans b[i][1]*a[j][0] b[i][1] [i] b i 1 a[j][0] [j] a j 0 b[i][0] -= a[j][0] b[i][0] [i] b i 0 a[j][0] [j] a j 0 a[j][0] = 0 a[j][0] [j] a j 0 0 j += 1 j 1 ans += b[i][1]*b[i][0] ans b[i][1]*b[i][0] b[i][1] [i] b i 1 b[i][0] [i] b i 0 a[j][0] -= b[i][0] a[j][0] [j] a j 0 b[i][0] [i] b i 0 b[i][0] = 0 b[i][0] [i] b i 0 0 i += 1 i 1 reg = j reg j if reg < len(a):
    for i in range(j, len(a)):
        ans += a[i][0]*a[i][1] reg < len(a) reg len(a) len a for i in range(j, len(a)):
        ans += a[i][0]*a[i][1] i range(j, len(a)) range j len(a) len a ans += a[i][0]*a[i][1] ans a[i][0]*a[i][1] a[i][0] [i] a i 0 a[i][1] [i] a i 1 print(ans) print ans def LIST()  : return list(MAP()) def LIST()  : return list(MAP()) LIST i += 1 1 i aa = Counter(LIST()) Counter(LIST()) aa reg = j j reg ans += a[i][0]*a[i][1] a[i][0]*a[i][1] ans j = 0 0 j aa = sorted(aa.items(), key=itemgetter(0)) sorted(aa.items(), key=itemgetter(0)) aa ans += b[i][1]*a[j][0] b[i][1]*a[j][0] ans def input() : return sys.stdin.readline().strip() def input() : return sys.stdin.readline().strip() input j += 1 1 j b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True) sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True) b m = MAP() MAP() m def INT()   : return int(input()) def INT()   : return int(input()) INT n, m = MAP() MAP() n ans += b[i][1]*b[i][0] b[i][1]*b[i][0] ans i = j = 0 0 i ans = 0 0 ans a = [[aa[i][1], aa[i][0]] for i in range(len(aa))] [[aa[i][1], aa[i][0]] for i in range(len(aa))] a def MAP()   : return map(int,input().split()) def MAP()   : return map(int,input().split()) MAP
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
aa = Counter(LIST())
aa = sorted(aa.items(), key=itemgetter(0))
a = [[aa[i][1], aa[i][0]] for i in range(len(aa))]
b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True)

ans = 0
i = j = 0
while i < len(b) and j < len(a) and b[i][1] > a[j][1]:
    if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1
reg = j
if reg < len(a):
    for i in range(j, len(a)):
        ans += a[i][0]*a[i][1]
print(ans)