#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=1e5+7;
int n,s,m,c;
vector<int>mach;
signed main(){
cin>>n>>s;
int mx=0;
for(int i=0; i<n; i++){
int x;
cin>>x;
mach.pb(x);
}
sort(mach.begin(), mach.end(), greater<int>());
while(s--){
int m,c;
cin>>m>>c;
vector<int> chn;
int x=0, y=c;
while(x<c&&y<n){
if(mach[x]-m>mach[y]) {chn.pb(mach[x]-m); x++;}
else {chn.pb(mach[y]); y++;}
}
while(x<c) {chn.pb(mach[x]-m); x++;}
while(y<n){chn.pb(mach[y]); y++;}
mach=chn;
}
for(auto i: mach)
cout<<i<<" ";
cout<<endl;
}