Problem: A parking lot in the City consists of n parking spaces, standing in a line. The parking spaces are numbered from 1 to n from left to right. 

When a car arrives at the lot, the operator determines an empty parking space for it. For the safety's sake the chosen place should be located as far from the already occupied places as possible. That is, the closest occupied parking space must be as far away as possible. If there are several such places, then the operator chooses the place with the minimum index from them. If all parking lot places are empty, then the car gets place number 1.

We consider the distance between the i-th and the j-th parking spaces equal to 4·|i - j| meters.

You are given the parking lot records of arriving and departing cars in the chronological order. For each record of an arriving car print the number of the parking lot that was given to this car.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 2·105) — the number of parking places and the number of records correspondingly. 

Next m lines contain the descriptions of the records, one per line. The i-th line contains numbers ti, idi (1 ≤ ti ≤ 2; 1 ≤ idi ≤ 106). If ti equals 1, then the corresponding record says that the car number idi arrived at the parking lot. If ti equals 2, then the corresponding record says that the car number idi departed from the parking lot. 

Records about arriving to the parking lot and departing from the parking lot are given chronologically. All events occurred consecutively, no two events occurred simultaneously.

It is guaranteed that all entries are correct: 

  * each car arrived at the parking lot at most once and departed from the parking lot at most once, 
  * there is no record of a departing car if it didn't arrive at the parking lot earlier, 
  * there are no more than n cars on the parking lot at any moment. 



You can consider the cars arbitrarily numbered from 1 to 106, all numbers are distinct. Initially all places in the parking lot are empty.

Output

For each entry of an arriving car print the number of its parking space. Print the numbers of the spaces in the order, in which the cars arrive to the parking lot.

Examples

Input

7 11
1 15
1 123123
1 3
1 5
2 123123
2 15
1 21
2 3
1 6
1 7
1 8


Output

1
7
4
2
7
4
1
3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 4;
const int K = 26;
const int inf = (int)1e9 + 7;
struct seg {
  int s, l, r;
  seg() {}
  seg(int s, int l, int r) : s(s), l(l), r(r) {}
  bool operator<(const seg& a) const {
    if ((s - 1) / 2 == (a.s - 1) / 2) {
      return l > a.l;
    } else {
      return (s - 1) / 2 < (a.s - 1) / 2;
    }
  }
};
struct ot {
  int s, l, r;
  ot() {}
  ot(int s, int l, int r) : s(s), l(l), r(r) {}
  bool operator<(const ot& a) const {
    if (l == a.l) {
      return r < a.r;
    } else {
      return l < a.l;
    }
  }
};
int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  set<seg> q;
  set<ot> p;
  map<int, int> m;
  p.insert(ot(n, 0, n - 1));
  for (int i = 0; i < w; ++i) {
    int t, id;
    scanf("%d%d", &t, &id);
    t--;
    id--;
    if (t == 0) {
      set<ot>::iterator it1 = p.begin();
      set<ot>::iterator it2 = p.end();
      set<seg>::iterator it3 = q.end();
      it2--;
      if ((int)q.size() > 0) {
        it3--;
      }
      if (it1->l == 0 && (it2->r != n - 1 || it1->s >= it2->s) &&
          (it3 == q.end() || it1->s >= (it3->s + 1) / 2)) {
        m[id] = 0;
        ot k = ot(it1->s - 1, it1->l + 1, it1->r);
        p.erase(it1);
        if (k.s > 0 && k.r < n - 1) {
          q.insert(seg(k.s, k.l, k.r));
        }
        if (k.s > 0) {
          p.insert(k);
        }
        printf("%d\n", 1);
        continue;
      }
      if (it3 != q.end() && (it1->l != 0 || (it3->s + 1) / 2 >= it1->s) &&
          (it2->r != n - 1 || (it3->s + 1) / 2 >= it2->s)) {
        int x = (it3->l + it3->r) / 2;
        ot a = ot(x - it3->l, it3->l, x - 1), b = ot(it3->r - x, x + 1, it3->r);
        m[id] = x;
        p.erase(ot(it3->s, it3->l, it3->r));
        q.erase(it3);
        if (a.s > 0) {
          p.insert(a);
          q.insert(seg(a.s, a.l, a.r));
        }
        if (b.s > 0) {
          p.insert(b);
          q.insert(seg(b.s, b.l, b.r));
        }
        printf("%d\n", ++x);
        continue;
      }
      if (it2->r == n - 1 && (it1->l != 0 || it2->s >= it1->s) &&
          (it3 == q.end() || it2->s >= (it3->s + 1) / 2)) {
        m[id] = n - 1;
        ot k = ot(it2->s - 1, it2->l, it2->r - 1);
        p.erase(it2);
        if (k.s > 0 && k.l > 0) {
          q.insert(seg(k.s, k.l, k.r));
        }
        if (k.s > 0) {
          p.insert(k);
        }
        printf("%d\n", n);
        continue;
      }
    } else {
      int x = m[id];
      if ((int)p.size() == 0) {
        if (x > 0 && x < n - 1) {
          q.insert(seg(1, x, x));
        }
        p.insert(ot(1, x, x));
        continue;
      }
      set<ot>::iterator it1 = p.lower_bound(ot(1, x, x));
      set<ot>::iterator it2 = p.upper_bound(ot(1, x, x));
      if (it1 == p.begin()) {
        if (it1->l == x + 1) {
          if (it1->l > 0 && it1->r < n - 1) {
            q.erase(seg(it1->s, it1->l, it1->r));
          }
          ot k = ot(it1->s + 1, it1->l - 1, it1->r);
          p.erase(it1);
          p.insert(k);
          if (k.r < n - 1 && k.l > 0) {
            q.insert(seg(k.s, k.l, k.r));
          }
        } else {
          if (x > 0 && x < n - 1) {
            q.insert(seg(1, x, x));
          }
          p.insert(ot(1, x, x));
        }
        continue;
      }
      it1--;
      if (it2 == p.end()) {
        if (it1->r == x - 1) {
          if (it1->l > 0 && it1->r < n - 1) {
            q.erase(seg(it1->s, it1->l, it1->r));
          }
          ot k = ot(it1->s + 1, it1->l, it1->r + 1);
          p.erase(it1);
          p.insert(k);
          if (k.r < n - 1 && k.l > 0) {
            q.insert(seg(k.s, k.l, k.r));
          }
        } else {
          if (x > 0 && x < n - 1) {
            q.insert(seg(1, x, x));
          }
          p.insert(ot(1, x, x));
        }
        continue;
      }
      if (it1->r == x - 1 && it2->l == x + 1) {
        if (it1->l > 0 && it1->r < n - 1) {
          q.erase(seg(it1->s, it1->l, it1->r));
        }
        if (it2->l > 0 && it2->r < n - 1) {
          q.erase(seg(it2->s, it2->l, it2->r));
        }
        ot a = ot(it2->r - it1->l + 1, it1->l, it2->r);
        p.erase(it1);
        p.erase(it2);
        p.insert(a);
        if (a.l > 0 && a.r < n - 1) {
          q.insert(seg(a.s, a.l, a.r));
        }
        continue;
      }
      if (it1->r == x - 1) {
        if (it1->l > 0 && it1->r < n - 1) {
          q.erase(seg(it1->s, it1->l, it1->r));
        }
        ot a = ot(x - it1->l + 1, it1->l, x);
        p.erase(it1);
        p.insert(a);
        if (a.l > 0 && a.r < n - 1) {
          q.insert(seg(a.s, a.l, a.r));
        }
        continue;
      }
      if (it2->l == x + 1) {
        if (it2->l > 0 && it2->r < n - 1) {
          q.erase(seg(it2->s, it2->l, it2->r));
        }
        ot a = ot(it2->r - x + 1, x, it2->r);
        p.erase(it2);
        p.insert(a);
        if (a.l > 0 && a.r < n - 1) {
          q.insert(seg(a.s, a.l, a.r));
        }
        continue;
      }
      p.insert(ot(1, x, x));
      if (x > 0 && x < n - 1) {
        q.insert(seg(1, x, x));
      }
    }
  }
  return 0;
}