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.
//package c;

import java.io.IOException;
import java.util.InputMismatchException;
import java.util.TreeSet;


public class q3 
{


	
	   public static void main(String args[])
	   {
		   FasterScanner s=new FasterScanner(); 
		   int n=s.nextInt();
		   int m=s.nextInt();
		   long a[]=new long[n];
		   for(int i=0;i<n;i++)
		   {
			   a[i]=s.nextLong();
		   }
		   int[] index=new int[n];
		   int[] ty=new int[n];
		   TreeSet<q> t=new TreeSet<q3.q>();
		   t.add(new q(-1,-1,-1));
		   for(int i=0;i<m;i++)
		   {
			   int type=s.nextInt();
			   int max=s.nextInt()-1;
			   int n1=i+1;
			   q tmp=new q(max,type,n1);
			   t.add(tmp);	 
			   index[max]=i+1;
			   ty[max]=type;
		   }
		   for(int i=n-2;i>=0;i--)
		   {
			   if(ty[i]==0)
				   ty[i]=ty[i+1];
		   }
		   q mqx=t.pollLast();
		   TreeSet<no> nom=new  TreeSet<no>();
		   for(int i=mqx.max;i>=0;i--)
		   {
			   no tmp=new no(a[i],i);
			   nom.add(tmp);
		   }
		//   System.out.println(nom.toString());
		   long[] ans=new long[n];
		   int tmpmax=0;
		   int maxty=0;
		   for(int i=n-1;i>=0;i--)
		   {
			   if(ty[i]==0)
				   ans[i]=a[i];
			   else
			   {
				   if(index[i]>tmpmax)
				   {
					   tmpmax=index[i];
					   maxty=ty[i];
				   }
				   if(maxty==1)
					   ans[i]=nom.pollLast().n;
				   else
					   ans[i]=nom.pollFirst().n;
			   }
		   }
		   
		   
		   
//		   for(int i=n-1;i>mqx.max;i--)
//			   ans[i]=a[i];
//		   q tmpq=t.pollLast();
//		   for(int i=mqx.max;i>=0;i--)
//		   {
//			  // System.out.println("i= "+i+" \n" +mqx+" "+tmpq+" "+nom+" "+t);
//			   if(i>tmpq.max)
//			   { if(mqx.type==1)
//				   ans[i]=nom.pollLast().n;
//			   else
//				   ans[i]=nom.pollFirst().n;}
//			   else
//			   {
//				   mqx=tmpq;
//				   tmpq=t.pollLast();
//				   if(mqx.type==1)
//					   ans[i]=nom.pollLast().n;
//				   else
//					   ans[i]=nom.pollFirst().n;
//			   }
//		   }
		   for(int i=0;i<n;i++)
		   System.out.print(ans[i]+" ");
		}
	   
	   	static class no implements Comparable<no>{
	   		long n;
	   		int k;
	   		public no(long n,int k)
	   		{
	   			this.n=n;
	   			this.k=k;
	   		}
			@Override
			public int compareTo(no o) {
				// TODO Auto-generated method stub
				if(this.n!=o.n)
					return (int)(this.n-o.n);
				else
					return this.k-o.k;
			}
			
			public String toString()
			{
				return this.n+" ";
			}
			
	   		
	   	}
	   	static class q implements Comparable<q>
	   	{
	   		int n;
	   		int type;
	   		int max;
	   		public String toString()
	   		{
	   			return " s "+n+" "+type+" "+max+" e ";
	   		}
	   		public q(int max,int type,int n)
	   		{
	   			this.n=n;
	   			this.max=max;
	   			this.type=type;
	   		}
			@Override
			public int compareTo(q o) {
				// TODO Auto-generated method stub
				if(this.max-o.max!=0)
				{
					return this.max-o.max;
				}
				else
					{
					if(this.n>o.n)
						{
						o.type=this.type;
						return 0;
						}
					else
					{
						this.type=o.type;
						return 0;
					}
					
//					int mt=this.type;
//					int ot=o.type;
//					if(o.n>this.n)
//					{
//						o.type=ot;
//						this.type=ot;
//					}
//					else
//					{
//						o.type=mt;
//						this.type=mt;
//					}
//					return 0;
					
					}
			}
	   	}
		public static long gcd(long a, long b) 
		{

			if(a==b)
				return a;
			if(a==0)
				return b;
			if(b==0)
				return a;

			if(a>b)
				return gcd(b,a%b);
			else
				return gcd(a,b%a);
		}

		public static long modPow( long a, long b, long mod )
	    {
	    	long res=1,pow=a;
	    	while( b>0 )
	    	{
	    		if( (b&1)==1 )
	    		{
	    			res = (pow*res)%mod;
	    		}
	    		pow = (pow*pow)%mod;
	    		b=b/2;
	    	}
	    	return res;
	    }
		
		static class nck
		{
			public static long ncr[][];
			
			public nck(long z,long p)//z==maxvalue  p==mod
			{
				generateNCR(z, p);
			}
			
		    private static void generateNCR( long z, long p )
		    {
		    	ncr = new long[(int)z+1][(int)z+1];
		    	ncr[0][0] = 1;
		    	for(int i=1; i<=z; i++)
		    	{
		    		ncr[i][0] = 1;
		    		ncr[0][i] = 0;
		    	}
		        for(int i=1; i<=z; i++)
		        {
		            for(int j=1; j<=z; j++)
		            {
		                ncr[i][j] = (ncr[i-1][j] + ncr[i-1][j-1]) % p;
		            }
		        }
		    }

		    private static long lucas(long n, long k, long p) 
		    {
		    
		        long ans = 1;
		        
		        while(n>0)
		        {
		            int N = (int)(n%p);
		            int K = (int)(k%p);
		            if(K>N)
		                return 0;
		            ans *= (ncr[N][K] );
		            n /= p;
		            k /= p;
		        }
		        return ans % p;
			
	    }
		}
		
		
		

		
		

		
		
		
		
		static class SegTree
		{
			static int seg[];
			static int dp[];
			int n;
			int d;
			public SegTree(int[] arr,int defaul)
			{
				this.dp=arr;
				n=dp.length;
				seg=new int[4*arr.length];
				build(1,0,n);
				this.d=defaul;
			}

			public void build(int id,int l,int r){
				if(r-l<2){
					seg[id]=dp[l];
					return;
				}
				int mid=(l+r)/2;
				build(2*id,l,mid);
				build(2*id+1,mid,r);
				seg[id]=merge(seg[2*id],seg[2*id+1]);
			}

			public int query(int l,int r)
			{
				return givemin(1,l,r,0,n);
			}

			public  int givemin(int id,int x,int y,int l,int r){
				if(x<=l && y>=r){
					return seg[id];
				}
				if(y<=l || r<=x){
					return d;
				}
				int mid=(l+r)/2;
				return merge(givemin(2*id, x, y, l, mid),givemin(2*id+1, x, y, mid, r));
			}

			public int upd(int id,int value)
			{
				return update(1,id,value,0,n);
			}
			public  int update(int id,int p,int value,int l,int r){
				if(r-l<2){
					dp[p]=value;
					seg[id]=value;
					return value;
				}
				int mid=(l+r)/2;
				if(p<mid){
					update(2*id, p, value, l, mid);
					seg[id]=merge(seg[2*id], seg[2*id+1]);
					return seg[id];
				}
				else{
					update(2*id+1, p, value, mid,r);
					seg[id]=merge(seg[2*id+1], seg[2*id]);
					return seg[id];

				}
			}

			public int merge(int l,int r)
			{

				//set initial value
				return l+r;
			}
		}


		static class UF {

			private int[] parent;  // parent[i] = parent of i
			private byte[] rank;   // rank[i] = rank of subtree rooted at i (never more than 31)
			private int count;   
			int[] seg;
			int max;
			// number of components
			public UF(int N) {
				if (N < 0) throw new IllegalArgumentException();
				count = N;
				parent = new int[N];
				rank = new byte[N];
				seg=new int[N];
				for (int i = 0; i < N; i++) {
					parent[i] = i;
					rank[i] = 0;
					seg[i]=1;
				}
				max=1;
			}

			public int find(int p) {
				if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
				while (p != parent[p]) {
					parent[p] = parent[parent[p]];    // path compression by halving
					p = parent[p];
				}
				return p;
			}
			public int count() {
				return count;
			}

			public boolean connected(int p, int q) {
				return find(p) == find(q);
			}

			public boolean union(int p, int q) {
				//    System.out.println("uf "+p+" "+q);
				int rootP = find(p);
				int rootQ = find(q);
				if (rootP == rootQ) return false;

				// make root of smaller rank point to root of larger rank
				if      (rank[rootP] < rank[rootQ])
				{
					parent[rootP] = rootQ;
					seg[rootQ]+=seg[rootP];
					max=Math.max(seg[rootQ],max);
				}
				else if (rank[rootP] > rank[rootQ])
				{
					parent[rootQ] = rootP;
					seg[rootP]+=seg[rootQ];
					max=Math.max(seg[rootP],max);
				}
				else {
					parent[rootQ] = rootP;
					rank[rootP]++;
					seg[rootP]+=seg[rootQ];
					max=Math.max(seg[rootP],max);
				}
				count--;
				return true;
			}

		}



		static class SparseTable
		{
			int[][] st;
			public SparseTable(int[] h){
				int n=h.length;
				int MAX_LOG=(int)Math.ceil(Math.log(n)/Math.log(2))+1;
				st=new int[n][MAX_LOG];
				for (int i = 0; i < n; i++)
					st[i][0] = h[i];
				for (int j = 1; (1 << j) <= n; j++)
				{
					for (int i = 0;( i + (1 << j) - 1 )< n; i++)
					{
						st[i][j]=Math.max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
					}
				}
			}
			public int query(int l,int r)
			{
				int x=(int )Math.floor((Math.log(r-l+1)/Math.log(2)));
				int ans=Math.max(st[l][x],st[r-(1<<x)+1][x]);
				return ans;
			}

		}

		public static class FasterScanner {
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;

			public int read() {
				if (numChars == -1)
					throw new InputMismatchException();
				if (curChar >= numChars) {
					curChar = 0;
					try {
						numChars = System.in.read(buf);
					} catch (IOException e) {
						throw new InputMismatchException();
					}
					if (numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}

			public String nextLine() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isEndOfLine(c));
				return res.toString();
			}

			public String nextString() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isSpaceChar(c));
				return res.toString();
			}

			public long nextLong() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = read();
				}
				long res = 0;
				do {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

			public int nextInt() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = read();
				}
				int res = 0;
				do {
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					res *= 10;
					res += c - '0';
					c = read();
				} while (!isSpaceChar(c));
				return res * sgn;
			}

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

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

			private boolean isSpaceChar(int c) {
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			private boolean isEndOfLine(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}
		}
}
