
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
struct p{
int val,cnt;
}a[1000000];
bool cmp(p a,p b)
{
return a.val>b.val;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
a[i].cnt = 1;
a[i].val = x;
}
int cur = n;
while(m--)
{
int b,c;
cin>>b>>c;
a[++cur].val = c;
a[++cur].cnt = b;
}
sort(a+1,a+cur,cmp);
long long ans = 0;
for(int i=1;;i++)
{
if(n>=a[i].cnt)
{
n-=a[i].cnt;
ans += 1ll*a[i].val*a[i].cnt;
}
else
{
ans += 1ll*a[i].val*n;
cout<<ans<<endl;
return 0;
}
// cout<<i<<" "<<ans<<endl;
}
}
过不了样例 所以不是数组大小这类问题 样例输入
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
输出
338