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 *r*<sub class="lower-index">*i*</sub> 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 *a*<sub class="lower-index">*i*</sub> of length *n* and the description of each manager, that is value *r*<sub class="lower-index">*i*</sub> and his favourite order. You are asked to speed up the process and determine how the final report will look like.
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 *a*<sub class="lower-index">*i*</sub> (|*a*<sub class="lower-index">*i*</sub>| ≤ 10<sup class="upper-index">9</sup>) — 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 *t*<sub class="lower-index">*i*</sub> and *r*<sub class="lower-index">*i*</sub> (<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4c7c768da8395489b31f8f3db90a6fe799bdeb0f.png" style="max-width: 100.0%;max-height: 100.0%;"/>, 1 ≤ *r*<sub class="lower-index">*i*</sub> ≤ *n*), meaning that the *i*-th manager sorts the first *r*<sub class="lower-index">*i*</sub> numbers either in the non-descending (if *t*<sub class="lower-index">*i*</sub> = 1) or non-ascending (if *t*<sub class="lower-index">*i*</sub> = 2) order.
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.
3 1
1 2 3
2 2
2 1 3 
4 2
1 2 4 3
2 3
1 2
2 4 1 3 
4 1
4 3 2 1
1 4
1 2 3 4 
5 1
1 2 3 4 5
2 5
5 4 3 2 1 
6 2
3 1 2 6 4 5
1 6
2 3
3 2 1 4 5 6 
10 3
6 4 0 2 -3 7 8 -9 1 5
1 8
1 4
2 2
-3 -9 0 2 4 6 7 8 1 5 
100 30
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66 1 36 44 43 82 37 38 106 27 114 51 112 55 87 41 69 31 86 58 27 46 99 18 105 91 38 5 9 2 109 39 2 27 47
2 38
2 32
1 46
1 37
1 20
1 5
2 42
2 18
1 35
1 36
2 44
1 36
1 20
2 21
2 14
1 13
2 2
1 15
2 50
2 35
1 42
1 21
1 50
2 50
1 1
2 48
2 24
1 34
1 23
2 9
65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56 49 103 61 66 1 36 44 43 82 37 38 106 27 114 51 112 55 87 41 69 31 86 58 27 46 99 18 105 91 38 5 9 2 109 39 2 27 47 
1 1
1234
1 1
1234 
1 1
1000000000
2 1
1000000000 
1 2
-1000000000
1 1
2 1
-1000000000 
30 13
15 44 5 56 84 15 24 72 97 3 61 97 36 33 98 49 1 40 76 94 7 46 85 53 79 68 78 54 80 33
2 18
1 9
1 6
2 30
2 15
2 4
2 17
2 16
2 20
2 16
2 7
2 12
1 20
40 44 46 49 53 54 56 61 68 72 76 78 79 80 84 85 94 97 97 98 36 33 33 24 15 15 7 5 3 1 
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
manager = []
for i in range(m):
    t = [int(j) for j in input().split()]
    manager.append(t)
manager.sort(key = lambda manager:manager[1],reverse = True)
result = []
if manager[0][1] < len(a):
    result.extend(a[manager[0][1]:])
    del(a[manager[0][1]:])
a.sort()
for i in range(m):
    if i < m - 1:
        if manager[i][1] == manager[i + 1][1]: continue
        if manager[i][0] == 1:
            for j in range(manager[i][1] - manager[i + 1][1]):
                result.insert(0,a[-1])
                del(a[-1])               
        elif manager[i][0] == 2:
            for j in range(manager[i][1] - manager[i + 1][1]):
                result.insert(0,a[0])
                del(a[0])
    else:
        if manager[i][0] == 1:
            a.extend(result)
            result = a
        elif manager[i][0] == 2:
            a.sort(reverse = True)
            a.extend(result)
            result = a
print(' '.join(map(str,result)))
