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;
double EPS = 1e-10;
double EQ(double a, double b) { return abs(a - b) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
set<pair<int, pair<int, int> > > usableRange;
set<int> usingPlaces;
int carPoses[2000000];
int N, M;
int calcRange(pair<int, int> p) {
  int from = p.first;
  int to = p.second;
  if (from == 1 || to == N) return -(to - from + 1);
  return -((to - from) / 2 + 1);
}
int main() {
  cin >> N >> M;
  memset(carPoses, 0, sizeof(carPoses));
  usableRange.insert(
      make_pair(calcRange(pair<int, int>(1, N)), pair<int, int>(1, N)));
  for (int i = 0; i < M; i++) {
    int t, id;
    cin >> t >> id;
    if (t == 1) {
      pair<int, pair<int, int> > p = *usableRange.begin();
      usableRange.erase(usableRange.begin());
      int insPos;
      if (p.second.first == 1) {
        insPos = 1;
        if (p.second.first < p.second.second)
          usableRange.insert(
              make_pair(calcRange(pair<int, int>(2, p.second.second)),
                        pair<int, int>(2, p.second.second)));
      } else if (p.second.second == N) {
        insPos = N;
        if (p.second.first < p.second.second)
          usableRange.insert(
              make_pair(calcRange(pair<int, int>(p.second.first, N - 1)),
                        pair<int, int>(p.second.first, N - 1)));
      } else {
        insPos = (p.second.first + p.second.second) / 2;
        pair<int, int> lftRange = pair<int, int>(p.second.first, insPos - 1);
        if (lftRange.first <= lftRange.second)
          usableRange.insert(make_pair(calcRange(lftRange), lftRange));
        pair<int, int> rhtRange = pair<int, int>(insPos + 1, p.second.second);
        if (rhtRange.first <= rhtRange.second)
          usableRange.insert(make_pair(calcRange(rhtRange), rhtRange));
      }
      carPoses[id] = insPos;
      usingPlaces.insert(insPos);
      cout << insPos << endl;
    } else {
      int pos = carPoses[id];
      set<int>::iterator it = usingPlaces.find(pos);
      if (*it == 1) {
        set<int>::iterator iit = it;
        int from = 1;
        int to;
        if (++iit == usingPlaces.end())
          to = N;
        else
          to = (*iit) - 1;
        usableRange.erase(make_pair(calcRange(pair<int, int>(from + 1, to)),
                                    pair<int, int>(from + 1, to)));
        usableRange.insert(make_pair(calcRange(pair<int, int>(from, to)),
                                     pair<int, int>(from, to)));
      } else if (*it == N) {
        set<int>::iterator iit = it;
        int to = N;
        int from;
        if (iit == usingPlaces.begin())
          from = 1;
        else
          from = (*(--iit)) + 1;
        usableRange.erase(make_pair(calcRange(pair<int, int>(from, to - 1)),
                                    pair<int, int>(from, to - 1)));
        usableRange.insert(make_pair(calcRange(pair<int, int>(from, to)),
                                     pair<int, int>(from, to)));
      } else {
        set<int>::iterator iit1 = it;
        iit1--;
        set<int>::iterator iit2 = it;
        iit2++;
        int mid = *it;
        int from;
        if (it == usingPlaces.begin())
          from = 1;
        else
          from = *iit1 + 1;
        int to;
        if (iit2 == usingPlaces.end())
          to = N;
        else
          to = (*iit2) - 1;
        if (from <= mid - 1) {
          if (from != 1)
            usableRange.erase(make_pair(-(((mid - 1 - from) / 2 + 1)),
                                        pair<int, int>(from, mid - 1)));
          else
            usableRange.erase(
                make_pair(-(mid - from), pair<int, int>(from, mid - 1)));
        }
        if (mid + 1 <= to) {
          if (to != N)
            usableRange.erase(make_pair(-(((to - mid - 1) / 2 + 1)),
                                        pair<int, int>(mid + 1, to)));
          else {
            usableRange.erase(
                make_pair(-((to - mid)), pair<int, int>(mid + 1, to)));
          }
        }
        if (to != N && from != 1)
          usableRange.insert(
              make_pair(-(((to - from) / 2 + 1)), pair<int, int>(from, to)));
        else
          usableRange.insert(
              make_pair(-(to - from + 1), pair<int, int>(from, to)));
      }
      usingPlaces.erase(it);
    }
  }
  return 0;
}