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.

/**
 *
 * @author meashish
 */
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Stack;

public class Main {

    InputReader in;
    Printer out;

    long MOD = 1000000007;

    private void start() throws Exception {
        int n = in.nextInt();
        int m = in.nextInt();

        Integer a[] = input(n);

//        Pair<Integer, Boolean> pair[] = new Pair[m];
//        int ind = 0;
        int max = -1;
        
        Stack<Pair<Integer, Boolean>> stack = new Stack<>();
        
        for (int i = 0; i < m; i++) {
            int tt = in.nextInt();
            int r = in.nextInt() - 1;

            while (!stack.isEmpty() && stack.peek().key <= r) {
                stack.pop();
            }
            stack.push(new Pair<>(r, tt == 1));
            max = Math.max(max, r);

//            pair[ind] = new Pair<>(r, tt == 1);
//            ind++;
        }
        //out.println(stack);
        m = stack.size();
        Pair<Integer, Boolean> pair[] = new Pair[m];
        int ind = 0;
        for (Pair<Integer, Boolean> pr: stack) {
            pair[ind++] = pr;
        }
        
//        m = ind;
//        out.println("m = " + m);
        Arrays.sort(pair, 0, m, (Pair<Integer, Boolean> t1, Pair<Integer, Boolean> t2) -> t1.key - t2.key);
        Arrays.sort(a, 0, pair[m - 1].key + 1);

        Pair<Integer, Integer> resp[] = new Pair[m];

        resp[m - 1] = new Pair<>(0, pair[m - 1].key);
        resp[m - 1].reverse = !pair[m - 1].value;

//        out.println("pp " + Arrays.toString(pair));
//        out.println("pairi " + pair[m - 1]);
        for (int i = m - 2; i >= 0; i--) {
//            out.println("pairi " + pair[i]);
            int diff = pair[i + 1].key - pair[i].key;

            int st = resp[i + 1].key;
            int en = resp[i + 1].value;

            if (resp[i + 1].reverse) {
                st += diff;
            }

//            out.println("diff " + diff + " " + pair[i + 1].key + " " + pair[i].key);
            resp[i] = new Pair<>(st, st + pair[i].key);
            resp[i].reverse = !pair[i].value;
        }

//        for (int i = 0; i < m; i++) {
//            out.println(resp[i].key + " " + resp[i].value + " " + resp[i].reverse);
//        }
        boolean mark[] = new boolean[n];
        Pair<Integer, Integer> res = resp[0];
        if (res.reverse) {
            for (int i = res.value; i >= res.key; i--) {
                mark[i] = true;
                out.print(a[i] + " ");
            }
        } else {
            for (int i = res.key; i <= res.value; i++) {
                mark[i] = true;
                out.print(a[i] + " ");
            }
        }
        for (int j = 1; j < m; j++) {
            res = resp[j];
            int start = res.key;
            int end = res.value;

//            if (res.reverse == resp[j - 1].reverse && res.reverse) {
//                start = resp[j - 1].value + 1;
//            }
//            if (res.reverse == resp[j - 1].reverse && !res.reverse) {
//                end = resp[j - 1].key - 1;
//            }
            if (mark[res.key]) {
                start = resp[j - 1].value + 1;
            }
            if (mark[res.value]) {
                end = resp[j - 1].key - 1;
            }

            if (res.reverse) {
                for (int i = end; i >= start; i--) {
                    if (mark[i]) {
                        break;
                    }
                    mark[i] = true;
                    out.print(a[i] + " ");
                }
            } else {
                for (int i = start; i <= end; i++) {
                    if (mark[i]) {
                        break;
                    }
                    mark[i] = true;
                    out.print(a[i] + " ");
                }
            }
        }
        for (int i = 0; i < n; i++) {
            if (!mark[i]) {
                out.print(a[i] + " ");
            }
        }
        out.println();
        //brute(n, m, a, pair);
    }

    void brute(int n, int m, Integer a[], Pair<Integer, Boolean> pair[]) {
        String s = out.buffer.toString();
        out.flush();
        for (int i = m - 1; i >= 0; i--) {
            int r = pair[i].key;
//            out.println(pair[i].value + " " + pair[i].key);
            if (pair[i].value) {
                Arrays.sort(a, 0, r + 1);
            } else {
                Arrays.sort(a, 0, r + 1, (Integer t, Integer t1) -> t1 - t);
            }
        }
        for (int i = 0; i < n; i++) {
            out.print(a[i] + " ");
        }
        out.println();
        
        String s2 = out.buffer.toString();
        out.println(s.equals(s2));
    }

    long power(long x, long n) {
        if (n <= 0) {
            return 1;
        }
        long y = power(x, n / 2);

        if ((n & 1) == 1) {
            return (((y * y) % MOD) * x) % MOD;
        }

        return (y * y) % MOD;
    }

    public int gcd(int a, int b) {
        a = Math.abs(a);
        b = Math.abs(b);
        return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
    }

    public Integer[] input(int n) {
        Integer a[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        return a;
    }

    public static void main(String[] args) throws Exception {
        InputReader in;
        PrintStream out;

//        in = new InputReader(new FileInputStream(new File("in.txt")));
        //out = new PrintStream("out.txt");
        in = new InputReader(System.in);
        out = System.out;

        Main main = new Main();

        main.in = in;
        main.out = new Printer(out);

        main.start();
        main.out.flush();
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

        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 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 double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private static class Printer {

        PrintStream out;
        StringBuilder buffer = new StringBuilder();
        boolean autoFlush;

        public Printer(PrintStream out) {
            this.out = out;
        }

        public Printer(PrintStream out, boolean autoFlush) {
            this.out = out;
            this.autoFlush = autoFlush;
        }

        public void println() {
            buffer.append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void println(int n) {
            println(Integer.toString(n));
        }

        public void println(long n) {
            println(Long.toString(n));
        }

        public void println(double n) {
            println(Double.toString(n));
        }

        public void println(float n) {
            println(Float.toString(n));
        }

        public void println(boolean n) {
            println(Boolean.toString(n));
        }

        public void println(char n) {
            println(Character.toString(n));
        }

        public void println(byte n) {
            println(Byte.toString(n));
        }

        public void println(short n) {
            println(Short.toString(n));
        }

        public void println(Object o) {
            println(o.toString());
        }

        public void println(Object[] o) {
            println(Arrays.deepToString(o));
        }

        public void println(String s) {
            buffer.append(s).append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void print(char s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void print(String s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void flush() {
            try {
                BufferedWriter log = new BufferedWriter(new OutputStreamWriter(out));
                log.write(buffer.toString());

                log.flush();
                buffer = new StringBuilder();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private class Pair<T, U> implements Serializable {

        boolean reverse;
        private T key;

        public T getKey() {
            return key;
        }

        private U value;

        public U getValue() {
            return value;
        }

        public Pair(T key, U value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }

            final Pair other = (Pair) obj;
            if (!this.key.equals(other.key)) {
                return false;
            }

            return this.value.equals(other.value);
        }

        @Override
        public int hashCode() {
            return key.hashCode() + 13 * value.hashCode();
        }
    }

    private class PairSet<T, S> {

        HashMap<T, HashSet<S>> map = new HashMap<>();

        public void add(T a, S b) {
            if (map.containsKey(a)) {
                map.get(a).add(b);
            }

            HashSet<S> set = new HashSet<>();
            set.add(b);
            map.put(a, set);
        }

        public boolean contains(T a, S b) {
            if (map.containsKey(a)) {
                return map.get(a).contains(b);
            }

            return false;
        }
    }

    private class Bit {

        int N;
        long ft1[], ft2[];

        Bit(int n) {
            N = n;
            ft1 = new long[N + 1];
            ft2 = new long[N + 1];
        }

        void update(long ft[], int p, long v) {
            for (; p <= N; p += p & (-p)) {
                ft[p] += v;
//                ft[p] %= MOD;
            }
        }

        void update(int a, int b, long v) {
            update(ft1, a, v);
            update(ft1, b + 1, -v);
            update(ft2, a, v * (a - 1));
            update(ft2, b + 1, -v * b);
        }

        long query(long ft[], int b) {
            long sum = 0;
            for (; b > 0; b -= b & (-b)) {
                sum += ft[b];
//                sum %= MOD;
            }

            return sum;
        }

        long query(int b) {
            return query(ft1, b) * b - query(ft2, b);
        }

        long query(int a, int b) {
            return query(b) - query(a - 1);
        }
    }
}
