Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of m managers. Each of them may reorder the elements in some order. Namely, the i-th manager either sorts first ri numbers in non-descending or non-ascending order and then passes the report to the manager i + 1, or directly to Blake (if this manager has number i = m).

Employees of the "Blake Technologies" are preparing the report right now. You know the initial sequence ai of length n and the description of each manager, that is value ri and his favourite order. You are asked to speed up the process and determine how the final report will look like.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of commodities in the report and the number of managers, respectively.

The second line contains n integers ai (|ai| ≤ 109) — the initial report before it gets to the first manager.

Then follow m lines with the descriptions of the operations managers are going to perform. The i-th of these lines contains two integers ti and ri (<image>, 1 ≤ ri ≤ n), meaning that the i-th manager sorts the first ri numbers either in the non-descending (if ti = 1) or non-ascending (if ti = 2) order.

Output

Print n integers — the final report, which will be passed to Blake by manager number m.

Examples

Input

3 1
1 2 3
2 2


Output

2 1 3 

Input

4 2
1 2 4 3
2 3
1 2


Output

2 4 1 3 

Note

In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.

In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the report changed to: 2 4 1 3. This report was handed over to Blake.
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int bs=1000;
 int n=ir.nextInt();
 int m=ir.nextInt();
 int[] a=ir.nextIntArray(n);
 int[][] q=new int[m][];
 for(int i=0;i<m;i++){
  q[i]=new int[]{ir.nextInt(),ir.nextInt(),i};
 }
 Arrays.sort(q,new Comparator<int[]>(){
  public int compare(int[] s,int[] t){
   if(s[1]!=t[1]) return -Integer.compare(s[1],t[1]);
   return -Integer.compare(s[2],t[2]);
  }
 });
 int[] ans=new int[n];
 for(int i=q[0][1];i<n;i++) ans[i]=a[i];
 int[] ca=new int[q[0][1]];
 for(int i=0;i<q[0][1];i++) ca[i]=a[i];
 mergeSort(ca);
 Deque<Integer> que=new ArrayDeque<>();
 for(int i=0;i<q[0][1];i++) que.offerLast(ca[i]);
 int now=0;
 int temp;
 while(true){
  temp=now;
  while(now<m){
   if(q[temp][2]>=q[now][2]||q[temp][1]==q[now][1]) now++;
   else break;
  }
  if(now==m){
   if(q[temp][0]==1){
    for(int i=0;i<q[temp][1];i++){
     ans[i]=que.pollFirst();
    }
   }
   else{
    for(int i=0;i<q[temp][1];i++){
     ans[i]=que.pollLast();
    }
   }
   break;
  }
  if(q[temp][0]==1){
   for(int i=q[temp][1]-1;i>=q[now][1];i--){
    ans[i]=que.pollLast();
   }
  }
  else{
   for(int i=q[temp][1]-1;i>=q[now][1];i--){
    ans[i]=que.pollFirst();
   }
  }
 }
 for(int i=0;i<n;i++) out.println(ans[i]+(i==n-1?"\n":" "));
}

static int[] buff;

static void __mergeSort(int[] a,int left,int right){
 if(left<right){
  int i,mid=(left+right)/2,p=0,j=0,k=left;
  __mergeSort(a,left,mid);
  __mergeSort(a,mid+1,right);
  for(i=left;i<=mid;i++)
    buff[p++]=a[i];
  while(i<=right&&j<p)
    a[k++]=(buff[j]<=a[i])?buff[j++]:a[i++];
  while(j<p)
    a[k++]=buff[j++];
 }
}
  
static void mergeSort(int[] a){
 buff=new int[a.length];
 __mergeSort(a,0,a.length-1);
 buff=null;
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public double nextDouble(){return Double.parseDouble(next());}

 public int[] nextIntArray(int n){
  int[] a=new int[n];
  for(int i=0;i<n;i++) a[i]=nextInt();
  return a;
 }

 public long[] nextLongArray(int n){
  long[] a=new long[n];
  for(int i=0;i<n;i++) a[i]=nextLong();
  return a;
 }

 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}