// اَللَهُمَ صَلِ عَلَىَ مُحَمَدٍ وَ آلِ مُحَمَدٍ
#include "bits/stdc++.h"
using namespace std ;
#define int long long
#define pb push_back
#define si size()
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define applejuice ios::sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ;
const int inf=1e18 ;
const int mod=1e9+7 ;
const int maxn=5*1e5+7 ;
int tt=1 ;
int a[maxn] , cnt[1007] ;
void solve() {
int n , s ;
cin >> n >> s ;
fill(cnt,cnt+1007,0) ;
for(int i=0 ; i<n ; i++) {cin >> a[i] ; cnt[a[i]]+=1 ;}
while(s--) {
cout << endl ;
int m , c ;
cin >> m >> c ;
vector<pair<int,int>> v ;
for(int i=1000 ; i>=0 ; i--) {
if(cnt[i]>=c) {
v.pb({i,c}) ;
c=0 ;
break ;
}
else if(cnt[i]>0) {
v.pb({i,cnt[i]}) ;
c-=cnt[i] ;
}
}
for(int i=0 ; i<v.si ; i++) {
cnt[v[i].fi]-=v[i].se ;
cnt[v[i].fi-m]+=v[i].se ;
}
}
for(int i=1000 ; i>=0 ; i--) {
while(cnt[i]--) {
cout << i << " " ;
}
}
}
signed main() {
//wrong
applejuice ;
//cin >> tt ;
while(tt--) {solve() ;}
}
/*
5 4
20 12 10 15 18
3 4
4 1
1 3
4 2
*/