'use strict';
(function(input){
  input=input.trim().split(/\n/);
  input=input.map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0],M=input[0][1];
  input.shift();
  const A=input[0];
  A.sort((a,b)=>a-b);
  input.shift();
  let counter=N;
  let last=0;
  let ans=0;
  input.sort((a,b)=>a[1]-b[1]);
  while((counter>0)&&(A.length>0)&&(input.length>0)){
    if(A[A.length-1]>=input[input.length-1][1]){
      counter--;
      ans+=A.pop();
      continue;
    }else{
      let BC=input.pop();
      counter-=BC[0];
      ans+=BC[1];
      last=BC[1];
    }
  }
  if(counter>0){
    while(counter>0){
      counter--;
      ans+=A.pop();
    }
  }
  else{
     ans+=counter*last;
  }
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));
