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.*;
import java.util.*;


public class Main {
	private InputStream is;
	private PrintWriter out;
	int time = 0, DP[], start[], end[], dist[], black[], MOD = (int) (1e9 + 7), arr[], weight[][], x[], y[], parent[];
	int MAX = 100010, N, K;
	long red[], ans = Long.MAX_VALUE;

	ArrayList<Character>[] amp;
	ArrayList<Pair>[] pmp;
	boolean b[][], boo[][], b1[];
	Pair prr[];
	HashMap<Pair, Integer> hm = new HashMap();
	long Dp[][][][] = new long[110][110][12][12];

	void soln() {
		is = System.in;
		out = new PrintWriter(System.out);
		long s = System.currentTimeMillis();
		solve();

		// out.close();
		out.flush();
		// tr(System.currentTimeMillis() - s + "ms");
	}

	static class ST1 // min ST
	{
		long arr[], st[];
		int size;

		ST1(long a[]) {
			arr = a.clone();
			size = 10 * arr.length;
			st = new long[size];
			build(0, arr.length - 1, 1);
		}

		void build(int ss, int se, int si) {
			if (ss == se) {
				st[si] = arr[ss];
				return;
			}
			int mid = (ss + se) / 2;
			int val = 2 * si;
			build(ss, mid, val);
			build(mid + 1, se, val + 1);
			st[si] = Math.min(st[val], st[val + 1]);
		}

		void update(int ss, int se, int idx, long val, int si) {
			if (ss == se) {
				// if(si==idx+1)
				st[si] = val;
				return;
			}
			int mid = (ss + se) / 2;
			if (ss <= idx && idx <= mid) {
				update(ss, mid, idx, val, 2 * si);
			} else {
				update(mid + 1, se, idx, val, 2 * si + 1);
			}
			int v = 2 * si;
			st[si] = Math.min(st[v], st[v + 1]);
		}

		long get(int ss, int se, int l, int r, int si) {
			if (l > se || r < ss || l > r)
				return Long.MAX_VALUE / 1000;
			if (l <= ss && r >= se)
				return st[si];
			int mid = (ss + se) / 2;
			int val = 2 * si;
			return Math.min(get(ss, mid, l, r, val), get(mid + 1, se, l, r, val + 1));
		}
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					// new CODEFORCES().soln();
				} catch (Exception e) {
					System.out.println(e);
				}
			}
		}, "1", 1 << 26).start();
		new Main().soln();
	}

	int cost = 0, D[][];
	char ch[], ch1[];
	int hash = 29;
	TreeSet<Cell> ts;
	int x2, y2;
	HashSet<Integer>[] hs = (HashSet<Integer>[]) new HashSet[110];
	cell[] c;
	Pair[] p = new Pair[4];
	int B = (int) (1e8 + 7);
	void solve() 
	{
		int n = ni(), m= ni();
		int arr[] = na(n);
		Pair prr[] = new Pair[m];
		for(int i = 0; i<m;i++) {
			int t = ni(), d = ni();
			prr[i] = new Pair(d,t,i);
		}
		TreeSet<Pair> pq2 = new TreeSet<>();
		TreeSet<Pair> pq1 = new TreeSet<>(Collections.reverseOrder());
		Arrays.sort(prr);
		int ans[] = new int[n];
		int j = prr[0].u;
		for(int i = j;i<n;i++) {
			ans[i] = arr[i];
		}
		for(int i = 0;i<j;i++) {
			pq1.add(new Pair(arr[i],i));
			pq2.add(new Pair(arr[i],i));
		}
		//System.out.println(pq1);
		//System.out.println(pq2);
		int x = prr[0].v, v = prr[0].i;
		for(int i = 1; i<m;i++) {
		//	System.out.println(prr[i]);
			int c = prr[i].i;
			if(c<=v) continue;
			int u = prr[i].u;
			if(x==2) {
				while(j>u) {
					Pair p = pq1.pollFirst();
					pq2.pollLast();
					ans[--j] = p.u; 
				}
			}
			else {
				while(j>u) {
					Pair p = pq2.pollFirst();
					pq1.pollLast();
					ans[--j] = p.u; 
				}
			}
			x = prr[i].v;
			v = prr[i].i;
		}
			if(x==2) {
				while(j>0) {
					Pair p = pq1.pollFirst();
					pq2.pollLast();
					ans[--j] = p.u; 
				}
			}
			else {
				while(j>0) {
					Pair p = pq2.pollFirst();
					pq1.pollLast();
					ans[--j] = p.u; 
				}
			}
		
		for(int i : ans) {
			System.out.print(i+" ");
		}
	}
	
	void print(int[][] arr) {
		int seed = 110, n = arr.length - 220;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				System.out.print(arr[i + seed][j + seed] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}

	int recur(int i, int time) {
		if (i >= N)
			return 0;
		if (D[i][time] != -1)
			return D[i][time];
		if ((time + c[i].t) >= c[i].d)
			return D[i][time] = recur(i + 1, time);
		return D[i][time] = max(recur(i + 1, time), c[i].p + recur(i + 1, time + c[i].t));
	}

	static class cell implements Comparable<cell> {
		int t, d, p, i;

		cell(int t, int d, int p, int i) {
			this.t = t;
			this.p = p;
			this.d = d;
			this.i = i;
		}

		public int compareTo(cell other) {
			// return Integer.compare(val, other.val);
			return Long.compare(d, other.d);// != 0 ? (Long.compare(d, other.u)): (Long.compare(v,
											// other.v));//((Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)):
											// (Long.compare(v, other.v)))
			// &(Long.compare(u, other.v) != 0 ? (Long.compare(u, other.v)):
			// (Long.compare(v, other.u))));
		}

		public String toString() {
			return this.d + " " + this.t;
		}
	}

	long abs(long x) {
		return ((x > 0) ? x : -x);
	}

	long ret(int p) {
		if (p >= 0)
			return 0;
		else
			return 1;
	}

	long val(int p, int a, int b) {
		if (p >= 0) {
			return (a * 1l * p);
		}
		return (b * 1l * p);
	}

	void ternary_search(int l, int r) {
		// System.out.println(l+" "+r+" "+ans);
		// for(int i : arr) System.out.print(i+" ");
		// System.out.println();
		if (r >= l) {
			int mid1 = l + (r - l) / 3;
			int mid2 = r - (r - l) / 3;
			long cnt1 = 0, cnt2 = 0;
			cnt1 = compute(mid1);
			cnt2 = compute(mid2);
			// System.out.println(mid1+" "+ cnt1+" "+mid2+" "+cnt2);
			ans = Math.min(cnt1, cnt2);
			if (cnt1 < cnt2) {
				ternary_search(l, mid2 - 1);
			} else {
				ternary_search(mid1 + 1, r);
			}
		}
		return;
	}

	long compute(int x) {
		long ans = 0;
		int c = arr[0];
		for (int i = 1; i <= x; i++) {
			ans += max(c + 1 - arr[i], 0);
			c = max(c + 1, arr[i]);
		}
		int temp = arr[x];
		arr[x] = max(c + 1, arr[x]);
		// SSystem.out.println(arr[x]+" "+ans);
		c = arr[arr.length - 1];
		for (int i = arr.length - 1; i > x; i--) {
			ans += max(c + 1 - arr[i - 1], 0);
			c = max(c + 1, arr[i - 1]);
		}
		arr[x] = temp;
		return ans;
	}

	public int getParent(int x) {
		while (parent[x] != x) {
			parent[x] = parent[parent[x]];
			x = parent[x];
		}
		return x;
	}

	void getFactors(int n, int x) {
		for (int i = 1; i * i <= n; i++) {
			if (n % i == 0) {
				hs[x].add(i);
				hs[x].add(n / i);
			}
		}
	}

	void recur(int a, int b, int k) {
		if (k == 0) {
			if (a == x2 && b == y2)
				ans++;
			return;
		}
		recur(a, b + 1, k - 1);
		recur(a, b - 1, k - 1);
		recur(a + 1, b, k - 1);
		recur(a - 1, b, k - 1);
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	private class Cell implements Comparable<Cell> {
		int u, v, s;

		public Cell(int u, int v, int s) {
			this.u = u;
			this.v = v;
			this.s = s;
		}

		public int hashCode() {
			return Objects.hash();
		}

		public int compareTo(Cell other) {
			return (Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s))
					: (Long.compare(v, other.v) != 0 ? Long.compare(v, other.v) : Long.compare(u, other.u)))
					& ((Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s))
							: (Long.compare(u, other.v) != 0 ? Long.compare(u, other.v) : Long.compare(v, other.u))));
		}

		public String toString() {
			return this.u + " " + this.v;
		}
	}

	class Pair implements Comparable<Pair> {
		int u ,v,i;

		Pair(int u, int v) {
			this.u = u;
			this.i = v;
		}

		Pair(int u, int v, int i) {
			this.u = u;
			this.v = v;
			this.i = i;
		}

		public int hashCode() {
			return Objects.hash();
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return ((u == other.u && v == other.v));
		}

		public int compareTo(Pair other) {
			// return Integer.compare(val, other.val);
			return Long.compare(other.u, u) != 0 ? (Long.compare(other.u, u)) : (Long.compare(other.i, i));// ((Long.compare(u,
		
		}									
		public String toString() {
			return this.u + " " + this.v +" "+this.i;
		}
	}

	int max(int a, int b) {
		if (a > b)
			return a;
		return b;
	}

	static class FenwickTree {

		int[] array; // 1-indexed array, In this array We save cumulative
						// information to perform efficient range queries and
						// updates

		public FenwickTree(int size) {
			array = new int[size + 1];
		}

		public int rsq(int ind) {
			assert ind > 0;
			int sum = 0;
			while (ind > 0) {
				sum += array[ind];
				// Extracting the portion up to the first significant one of the
				// binary representation of 'ind' and decrementing ind by that
				// number
				ind -= ind & (-ind);
			}
			return sum;
		}

		public int rsq(int a, int b) {
			assert b >= a && a > 0 && b > 0;
			return rsq(b) - rsq(a - 1);
		}

		public void update(int ind, int value) {
			assert ind > 0;
			while (ind < array.length) {
				array[ind] += value;
				// Extracting the portion up to the first significant one of the
				// binary representation of 'ind' and incrementing ind by that
				// number
				ind += ind & (-ind);
			}
		}

		public int size() {
			return array.length - 1;
		}
	}

	void buildGraph(int n) {
		for (int i = 0; i < n; i++) {
			int x1 = ni(), y1 = ni(), z = ni();
			//pmp[x1].add(new Pair(y1, z));
		}
	}

	long modInverse(long a, long mOD2) {
		return power(a, mOD2 - 2, mOD2);
	}

	long power(long x, long y, long m) {
		if (y == 0)
			return 1;
		long p = power(x, y / 2, m) % m;
		p = (p * p) % m;

		return (y % 2 == 0) ? p : (x * p) % m;
	}

	public long gcd(long a, long b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class ST {
		int arr[], lazy[], n;

		ST(int a) {
			n = a;
			arr = new int[10 * n];
			lazy = new int[10 * n];
		}

		void up(int l, int r, int val) {
			update(0, n - 1, 0, l, r, val);
		}

		void update(int l, int r, int c, int x, int y, int val) {
			if (lazy[c] != 0) {
				lazy[2 * c + 1] += lazy[c];
				lazy[2 * c + 2] += lazy[c];
				if (l == r)
					arr[c] += lazy[c];
				lazy[c] = 0;
			}
			if (l > r || x > y || l > y || x > r)
				return;
			if (x <= l && y >= r)

			{
				lazy[c] += val;
				return;
			}
			int mid = l + r >> 1;
			update(l, mid, 2 * c + 1, x, y, val);
			update(mid + 1, r, 2 * c + 2, x, y, val);
			arr[c] = Math.max(arr[2 * c + 1], arr[2 * c + 2]);
		}

		int an(int ind) {
			return ans(0, n - 1, 0, ind);
		}

		int ans(int l, int r, int c, int ind) {
			if (lazy[c] != 0) {
				lazy[2 * c + 1] += lazy[c];
				lazy[2 * c + 2] += lazy[c];
				if (l == r)
					arr[c] += lazy[c];
				lazy[c] = 0;
			}
			if (l == r)
				return arr[c];
			int mid = l + r >> 1;
			if (mid >= ind)
				return ans(l, mid, 2 * c + 1, ind);
			return ans(mid + 1, r, 2 * c + 2, ind);
		}
	}

	public static int[] shuffle(int[] a, Random gen) {
		for (int i = 0, n = a.length; i < n; i++) {
			int ind = gen.nextInt(n - i) + i;
			int d = a[i];
			a[i] = a[ind];
			a[ind] = d;
		}
		return a;
	}

	long power(long x, long y, int mod) {
		long ans = 1;
		while (y > 0) {
			if (y % 2 == 0) {
				x = (x * x) % mod;
				y /= 2;
			} else {
				ans = (x * ans) % mod;
				y--;
			}
		}
		return ans;
	}

	// To Get Input
	// Some Buffer Methods
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}