#!/usr/bin/env python3

# input = stdin.readline

def solve(n,m,a,queries):
  res = 0
  cnt = 0
  queries += [[1,x] for x in a]
  queries = list(sorted(queries,key=lambda x: x[1],reverse=True))
  for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
  return res



def main():
  N,M = map(int,input().split())
  a = list(map(int,input().split()))
  queries = list(list(map(int,input().split())) for _ in range(M))
  print(solve(N,M,a,queries))

if __name__ == '__main__':
  main() def solve(n,m,a,queries):
  res = 0
  cnt = 0
  queries += [[1,x] for x in a]
  queries = list(sorted(queries,key=lambda x: x[1],reverse=True))
  for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
  return res solve res = 0 res 0 cnt = 0 cnt 0 [1,x] for x in a for x in a x a for x in a [1,x] 1 x queries += [[1,x] for x in a] queries [[1,x] for x in a] queries = list(sorted(queries,key=lambda x: x[1],reverse=True)) queries list(sorted(queries,key=lambda x: x[1],reverse=True)) list sorted(queries,key=lambda x: x[1],reverse=True) sorted queries key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
   query queries if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
   cnt >= n cnt n break res += query[1] * min(query[0],n-cnt) res query[1] * min(query[0],n-cnt) query[1] query 1 min(query[0],n-cnt) min query[0] query 0 n-cnt n cnt cnt += query[0] cnt query[0] query 0 return res res n n m m a a queries queries def main():
  N,M = map(int,input().split())
  a = list(map(int,input().split()))
  queries = list(list(map(int,input().split())) for _ in range(M))
  print(solve(N,M,a,queries)) 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 queries = list(list(map(int,input().split())) for _ in range(M)) queries list(list(map(int,input().split())) for _ in range(M)) list list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split print(solve(N,M,a,queries)) print solve(N,M,a,queries) solve N M a queries if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main def main():
  N,M = map(int,input().split())
  a = list(map(int,input().split()))
  queries = list(list(map(int,input().split())) for _ in range(M))
  print(solve(N,M,a,queries)) def main():
  N,M = map(int,input().split())
  a = list(map(int,input().split()))
  queries = list(list(map(int,input().split())) for _ in range(M))
  print(solve(N,M,a,queries)) main def solve(n,m,a,queries):
  res = 0
  cnt = 0
  queries += [[1,x] for x in a]
  queries = list(sorted(queries,key=lambda x: x[1],reverse=True))
  for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
  return res def solve(n,m,a,queries):
  res = 0
  cnt = 0
  queries += [[1,x] for x in a]
  queries = list(sorted(queries,key=lambda x: x[1],reverse=True))
  for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
  return res solve
#!/usr/bin/env python3

# input = stdin.readline

def solve(n,m,a,queries):
  res = 0
  cnt = 0
  queries += [[1,x] for x in a]
  queries = list(sorted(queries,key=lambda x: x[1],reverse=True))
  for query in queries:
    if cnt >= n:
      break
    else:
      res += query[1] * min(query[0],n-cnt)
      cnt += query[0]
  return res



def main():
  N,M = map(int,input().split())
  a = list(map(int,input().split()))
  queries = list(list(map(int,input().split())) for _ in range(M))
  print(solve(N,M,a,queries))

if __name__ == '__main__':
  main()
