import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():

    n, m = LI()
    a = LI()
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]

    for i in range(m):
        b[i], c[i] = LI()

    dic = collections.Counter(a)
    queue = collections.deque(sorted(list(set(a)|set(c))))

    mn = min(a)
    while queue[0] < mn:
        queue.popleft()

    for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
    ans = 0
    for k, v in dic.items():
        ans += k*v

    print(ans)

        


main() import bisect,collections,copy,itertools,math,string bisect collections copy itertools math string import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split()) LS def main():

    n, m = LI()
    a = LI()
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]

    for i in range(m):
        b[i], c[i] = LI()

    dic = collections.Counter(a)
    queue = collections.deque(sorted(list(set(a)|set(c))))

    mn = min(a)
    while queue[0] < mn:
        queue.popleft()

    for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
    ans = 0
    for k, v in dic.items():
        ans += k*v

    print(ans)

         main n, m = LI() n LI() LI m a = LI() a LI() LI 0 for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) 0 b = [0 for _ in range(m)] b [0 for _ in range(m)] 0 for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) 0 c = [0 for _ in range(m)] c [0 for _ in range(m)] for i in range(m):
        b[i], c[i] = LI()

     i range(m) range m b[i], c[i] = LI() b[i] b i LI() LI c[i] c i dic = collections.Counter(a) dic collections.Counter(a) collections.Counter collections Counter a queue = collections.deque(sorted(list(set(a)|set(c)))) queue collections.deque(sorted(list(set(a)|set(c)))) collections.deque collections deque sorted(list(set(a)|set(c))) sorted list(set(a)|set(c)) list set(a)|set(c) set(a) set a set(c) set c mn = min(a) mn min(a) min a while queue[0] < mn:
        queue.popleft()

     queue[0] < mn queue[0] queue 0 mn queue.popleft() queue.popleft queue popleft for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
     i range(m) range m cnt = 0 cnt 0 for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
         x queue if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
         x < c[i] x c[i] c i tem = dic[x] tem dic[x] dic x dic[x] = max(dic[x]-b[i], 0) dic[x] dic x max(dic[x]-b[i], 0) max dic[x]-b[i] dic[x] dic x b[i] b i 0 b[i] -= tem-dic[x] b[i] b i tem-dic[x] tem dic[x] dic x dic[c[i]] += tem-dic[x] dic[c[i]] dic c[i] c i tem-dic[x] tem dic[x] dic x if dic[x] == 0:
                    cnt += 1
                 dic[x] == 0 dic[x] dic x 0 cnt += 1 cnt 1 if b[i] == 0:
                    break
             b[i] == 0 b[i] b i 0 break break for _ in range(cnt):
            queue.popleft()
     _ range(cnt) range cnt queue.popleft() queue.popleft queue popleft ans = 0 ans 0 for k, v in dic.items():
        ans += k*v

     k v dic.items() dic.items dic items ans += k*v ans k*v k v print(ans) print ans main() main def S(): return sys.stdin.readline().rstrip() def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) LS def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI def main():

    n, m = LI()
    a = LI()
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]

    for i in range(m):
        b[i], c[i] = LI()

    dic = collections.Counter(a)
    queue = collections.deque(sorted(list(set(a)|set(c))))

    mn = min(a)
    while queue[0] < mn:
        queue.popleft()

    for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
    ans = 0
    for k, v in dic.items():
        ans += k*v

    print(ans)

         def main():

    n, m = LI()
    a = LI()
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]

    for i in range(m):
        b[i], c[i] = LI()

    dic = collections.Counter(a)
    queue = collections.deque(sorted(list(set(a)|set(c))))

    mn = min(a)
    while queue[0] < mn:
        queue.popleft()

    for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
    ans = 0
    for k, v in dic.items():
        ans += k*v

    print(ans)

         main
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():

    n, m = LI()
    a = LI()
    b = [0 for _ in range(m)]
    c = [0 for _ in range(m)]

    for i in range(m):
        b[i], c[i] = LI()

    dic = collections.Counter(a)
    queue = collections.deque(sorted(list(set(a)|set(c))))

    mn = min(a)
    while queue[0] < mn:
        queue.popleft()

    for i in range(m):
        cnt = 0
        for x in queue:
            if x < c[i]:
                tem = dic[x]
                dic[x] = max(dic[x]-b[i], 0)
                b[i] -= tem-dic[x]
                dic[c[i]] += tem-dic[x]
                if dic[x] == 0:
                    cnt += 1
                if b[i] == 0:
                    break
            else:
                break
        for _ in range(cnt):
            queue.popleft()
    ans = 0
    for k, v in dic.items():
        ans += k*v

    print(ans)

        


main()
