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.
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int SHIFT = 1e9;
template <typename T, bool MULTI = false, typename SIZE_T = int>
struct sms_mo {
  struct node {
    node* ch[2];
    SIZE_T cnt;
    char d;
    T v;
    node(int d_, T v_, SIZE_T cnt_) : cnt(cnt_), d(d_), v(v_) {
      ch[0] = ch[1] = NULL;
    }
    node(node* x, bool b = true) : cnt(x->cnt), d(x->d), v(x->v) {
      if (b)
        ch[0] = x->ch[0], ch[1] = x->ch[1];
      else
        ch[0] = ch[1] = NULL;
    }
    void update() {
      if (!ch[0] ^ !ch[1]) {
        for (int i = 0; i < 2; i++)
          if (ch[i]) {
            node* tmp = ch[i];
            ch[0] = tmp->ch[0], ch[1] = tmp->ch[1];
            d = tmp->d, v = tmp->v;
            cnt = tmp->cnt;
            delete tmp;
            return;
          }
      }
      cnt = 0;
      for (int i = 0; i < 2; i++)
        if (ch[i]) cnt += ch[i]->cnt;
    }
  };
  node* root;
  T N;
  char n;
  sms_mo() : root(NULL), N(0), n(0) {}
  ~sms_mo() {
    std::vector<node*> q = {root};
    while (q.size()) {
      node* x = q.back();
      q.pop_back();
      if (!x) continue;
      q.push_back(x->ch[0]), q.push_back(x->ch[1]);
      delete x;
    }
  }
  friend void swap(sms_mo& a, sms_mo& b) {
    std::swap(a.root, b.root), std::swap(a.N, b.N), std::swap(a.n, b.n);
  }
  sms_mo& operator=(const sms_mo& v) {
    sms_mo tmp = v;
    swap(tmp, *this);
    return *this;
  }
  SIZE_T size() const { return root ? root->cnt : 0; }
  SIZE_T count(node* x) const { return x ? x->cnt : 0; }
  void clear() {
    sms_mo tmp;
    swap(*this, tmp);
  }
  void expand(T v) {
    while (v >> n) n++, N = 2 * N + 1;
  }
  char msb(T v, char l, char r) {
    for (char i = r; i > l; i--)
      if (v >> i & 1) return i;
    return -1;
  }
  void cut(node* at, T v, char i, node* prev = NULL) {
    char d = msb(v ^ at->v, prev ? std::max(at->d, prev->d) : at->d, i);
    if (d == -1) {
      if (!prev or prev->d <= at->d) return;
      d = prev->d, v = ~at->v;
    }
    node* nxt = new node(at);
    at->ch[v >> d & 1] = NULL;
    at->ch[!(v >> d & 1)] = nxt;
    at->d = d;
  }
  node* insert(node* at, T v, SIZE_T qt, char i) {
    if (!at) return new node(-1, v, qt);
    cut(at, v, i);
    if (at->d == -1) {
      at->cnt += qt;
      if (!MULTI) at->cnt = 1;
      return at;
    }
    bool dir = v >> at->d & 1;
    at->ch[dir] = insert(at->ch[dir], v, qt, at->d - 1);
    at->update();
    return at;
  }
  void insert(T v, SIZE_T qt = 1) {
    expand(v);
    root = insert(root, v, qt, n - 1);
  }
  node* merge(node* l, node* r, char i) {
    if (!l or !r) return l ? l : r;
    cut(l, r->v, i, r), cut(r, l->v, i, l);
    if (l->d == -1) {
      if (MULTI) l->cnt += r->cnt;
      delete r;
      return l;
    }
    for (int j = 0; j < 2; j++) l->ch[j] = merge(l->ch[j], r->ch[j], l->d - 1);
    l->update(), delete r;
    return l;
  }
  void merge(sms_mo& s) {
    if (N > s.N) swap(*this, s);
    expand(s.N);
    root = merge(root, s.root, n - 1);
    s.root = NULL;
  }
  node* split(node*& x, SIZE_T k) {
    if (k <= 0 or !x) return NULL;
    node* ret = new node(x);
    ret->ch[0] = ret->ch[1] = NULL;
    ret->cnt = 0;
    if (x->d == -1)
      x->cnt -= k, ret->cnt += k;
    else {
      if (k <= count(x->ch[0]))
        ret->ch[0] = split(x->ch[0], k);
      else {
        ret->ch[1] = split(x->ch[1], k - count(x->ch[0]));
        std::swap(x->ch[0], ret->ch[0]);
      }
      ret->update(), x->update();
    }
    if (!x->cnt) delete x, x = NULL;
    return ret;
  }
  void split(SIZE_T k, sms_mo& s) {
    s.clear();
    s.root = split(root, std::min(k, size()));
    s.N = N, s.n = n;
  }
  void split_val(T k, sms_mo& s) { split(order_of_key(k), s); }
  void print_rec(node* x, bool reverse) {
    if (!x) return;
    if (x->d == -1) {
      for (int i = 0; i < x->cnt; i++) cout << x->v - SHIFT << " ";
      return;
    }
    if (!reverse)
      for (int i = 0; i < 2; i++) print_rec(x->ch[i], reverse);
    else
      for (int i = 1; i + 1; i--) print_rec(x->ch[i], reverse);
  }
  void print(bool reverse) { print_rec(root, reverse); }
};
std::mt19937 dyn_array_rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename SIZE_T = int,
          typename SET = sms_mo<T, true, SIZE_T>>
struct dyn_array {
  struct node {
    node *l, *r;
    int p;
    SIZE_T sz;
    bool rev;
    SET val;
    node(SET& v) : l(NULL), r(NULL), p(dyn_array_rng()), sz(1), rev(0) {
      swap(val, v);
    }
    node(node* x)
        : l(NULL), r(NULL), p(x->p), sz(x->sz), rev(x->rev), val(x->val) {}
    void update() {
      sz = val.size();
      if (l) sz += l->sz;
      if (r) sz += r->sz;
    }
  };
  node* root;
  dyn_array() { root = NULL; }
  ~dyn_array() {
    std::vector<node*> q = {root};
    while (q.size()) {
      node* x = q.back();
      q.pop_back();
      if (!x) continue;
      q.push_back(x->l), q.push_back(x->r);
      delete x;
    }
  }
  friend void swap(dyn_array& a, dyn_array& b) { std::swap(a.root, b.root); }
  void clear() {
    dyn_array tmp;
    swap(tmp, *this);
  }
  SIZE_T size(node* x) const { return x ? x->sz : 0; }
  SIZE_T size() const { return size(root); }
  void join(node* l, node* r, node*& i) {
    if (!l or !r) return void(i = l ? l : r);
    if (l->p > r->p)
      join(l->r, r, l->r), i = l;
    else
      join(l, r->l, r->l), i = r;
    i->update();
  }
  void concat(dyn_array& v) {
    join(root, v.root, root);
    v.root = NULL;
  }
  void split(node* i, node*& l, node*& r, SIZE_T idx) {
    if (!i) return void(r = l = NULL);
    if (size(i->l) + i->val.size() <= idx) {
      split(i->r, i->r, r, idx - size(i->l) - i->val.size());
      l = i;
    } else if (size(i->l) >= idx) {
      split(i->l, l, i->l, idx);
      r = i;
    } else {
      SET L;
      if (!i->rev)
        i->val.split(idx - size(i->l), L);
      else {
        i->val.split(i->val.size() - (idx - size(i->l)), L);
        swap(L, i->val);
      }
      node* novo = new node(L);
      novo->rev = i->rev;
      novo->l = i->l;
      i->l = NULL;
      novo->update();
      l = novo, r = i;
    }
    i->update();
  }
  void split(SIZE_T k, dyn_array& v) {
    v.clear();
    split(root, v.root, root, std::min(k, size()));
  }
  void push_back(T val, SIZE_T qt = 1) {
    SET v;
    v.insert(val, qt);
    node* i = new node(v);
    join(root, i, root);
  }
  void merge(node*& i, SET& v) {
    if (!i) return;
    merge(i->l, v), merge(i->r, v);
    v.merge(i->val);
    delete i;
    i = NULL;
  }
  void sort(bool reverse = false) {
    if (!root) return;
    merge(root->l, root->val);
    merge(root->r, root->val);
    root->rev = reverse;
    root->update();
  }
  void sort(SIZE_T l, SIZE_T r, bool reverse = false) {
    dyn_array L, M;
    split(r + 1, M);
    M.split(l, L);
    M.sort(reverse);
    L.concat(M);
    L.concat(*this);
    swap(*this, L);
  }
  void print_rec(node* x) {
    if (!x) return;
    print_rec(x->l);
    x->val.print(x->rev);
    print_rec(x->r);
  }
  void print() { print_rec(root); }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  dyn_array<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(SHIFT + x);
  }
  while (q--) {
    int t, r;
    cin >> t >> r;
    r--;
    v.sort(0, r, t - 1);
  }
  v.print();
  cout << '\n';
  exit(0);
}
