import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict


INF=10**20
def main():
    N,M=mi()
    A=list(mi())

    X = []
    for i in range(M):
        b,c=mi()
        X.append((c,b))
    
    X.sort(reverse=True)
    A.sort(reverse=True)

    xi = 0
    b = 0

    newA = []
    while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
    print(sum(newA) + sum(A))
        

        




if __name__ == "__main__":
    main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 def mi(): return map(int,input().split()) mi def ii(): return int(input()) ii def isp(): return input().split() isp def deb(text): print("-------\n{}\n-------".format(text)) deb text text class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict Counter def __init__(self):
        self.dict = {}

     __init__ self.dict = {} self.dict self dict {} self self def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

     add if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

     x in self.dict x self.dict self dict self self x x def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

     decrement self.dict[x] -= 1 self.dict[x] self.dict self dict x 1 if self.dict[x] <= 0:
            del self.dict[x]

     self.dict[x] <= 0 self.dict[x] self.dict self dict x 0 del self.dict[x] self.dict[x] self.dict self dict x self self x x def get_dict(self):
        return self.dict get_dict return self.dict self.dict self dict self self INF=10**20 INF 10**20 10 20 def main():
    N,M=mi()
    A=list(mi())

    X = []
    for i in range(M):
        b,c=mi()
        X.append((c,b))
    
    X.sort(reverse=True)
    A.sort(reverse=True)

    xi = 0
    b = 0

    newA = []
    while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
    print(sum(newA) + sum(A))
        

         main N,M=mi() N mi() mi M A=list(mi()) A list(mi()) list mi() mi X = [] X [] for i in range(M):
        b,c=mi()
        X.append((c,b))
    
     i range(M) range M b,c=mi() b mi() mi c X.append((c,b)) X.append X append (c,b) c b X.sort(reverse=True) X.sort X sort reverse=True reverse True A.sort(reverse=True) A.sort A sort reverse=True reverse True xi = 0 xi 0 b = 0 b 0 newA = [] newA [] while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
     A if not xi < len(X): break
        
         not xi < len(X) xi < len(X) xi len(X) len X if b == 0: c,b = X[xi]
         b == 0 b 0 a = A.pop() a A.pop() A.pop A pop if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

         a < c a c newA.append(c) newA.append newA append c A.append(a) A.append A append a b = 0 b 0 b -= 1 b 1 if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
     b <= 0 b 0 xi += 1 xi 1 print(sum(newA) + sum(A)) print sum(newA) + sum(A) sum(newA) sum newA sum(A) sum A if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def isp(): return input().split() def isp(): return input().split() isp def deb(text): print("-------\n{}\n-------".format(text)) def deb(text): print("-------\n{}\n-------".format(text)) deb def main():
    N,M=mi()
    A=list(mi())

    X = []
    for i in range(M):
        b,c=mi()
        X.append((c,b))
    
    X.sort(reverse=True)
    A.sort(reverse=True)

    xi = 0
    b = 0

    newA = []
    while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
    print(sum(newA) + sum(A))
        

         def main():
    N,M=mi()
    A=list(mi())

    X = []
    for i in range(M):
        b,c=mi()
        X.append((c,b))
    
    X.sort(reverse=True)
    A.sort(reverse=True)

    xi = 0
    b = 0

    newA = []
    while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
    print(sum(newA) + sum(A))
        

         main def ii(): return int(input()) def ii(): return int(input()) ii class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict Counter def mi(): return map(int,input().split()) def mi(): return map(int,input().split()) mi INF=10**20 10**20 INF
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

class Counter:
    def __init__(self):
        self.dict = {}

    def add(self,x):
        if x in self.dict: self.dict[x] += 1
        else: self.dict[x] = 1

    def decrement(self,x):
        self.dict[x] -= 1
        if self.dict[x] <= 0:
            del self.dict[x]

    def get_dict(self):
        return self.dict


INF=10**20
def main():
    N,M=mi()
    A=list(mi())

    X = []
    for i in range(M):
        b,c=mi()
        X.append((c,b))
    
    X.sort(reverse=True)
    A.sort(reverse=True)

    xi = 0
    b = 0

    newA = []
    while A:
        if not xi < len(X): break
        
        if b == 0: c,b = X[xi]
        a = A.pop() # 小さい順に

        # print(a,b,c)
        if a < c:   
            newA.append(c)
        else:
            A.append(a)
            b = 0

        b -= 1 
        if b <= 0:
            xi += 1
    
    # print(A)
    # print(newA)
    print(sum(newA) + sum(A))
        

        




if __name__ == "__main__":
    main()