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;
int inf = 987654321;
struct Node {
  int left_car, right_car, best_pos, best_dist, size;
  Node()
      : left_car(-inf), right_car(+inf), best_pos(0), best_dist(0), size(1) {}
  string str() const {
    ostringstream os;
    os << size << ' ' << left_car << ' ' << right_car << ' ' << best_pos << ' '
       << best_dist;
    return os.str();
  }
};
Node join(const Node &a, const Node &b) {
  Node res;
  if (a.left_car != -inf) {
    res.left_car = a.left_car;
  } else if (b.left_car != -inf) {
    res.left_car = a.size + b.left_car;
  } else {
    res.left_car = -inf;
  }
  if (b.right_car != +inf) {
    res.right_car = a.size + b.right_car;
  } else if (a.right_car != +inf) {
    res.right_car = a.right_car;
  } else {
    res.right_car = +inf;
  }
  res.size = a.size + b.size;
  res.best_pos = a.best_pos;
  res.best_dist = a.best_dist;
  if (b.best_dist > res.best_dist) {
    res.best_pos = a.size + b.best_pos;
    res.best_dist = b.best_dist;
  }
  int center_dist, center_pos;
  if (a.right_car == inf) {
    if (b.left_car == -inf) {
      center_dist = (res.size - 1) / 2;
      center_pos = center_dist;
    } else {
      center_dist = (a.size + b.left_car - 1) / 2;
      center_pos = center_dist;
    }
  } else if (b.left_car == -inf) {
    center_dist = (a.size - 1 - a.right_car + b.size - 1) / 2;
    center_pos = a.right_car + 1 + center_dist;
  } else {
    center_dist = (a.size + b.left_car - a.right_car - 2);
    if (center_dist < 0) {
      center_pos = inf;
    } else {
      center_dist /= 2;
      center_pos = a.right_car + 1 + center_dist;
    }
  }
  if (center_dist > res.best_dist ||
      (center_dist == res.best_dist && center_pos < res.best_pos)) {
    res.best_pos = center_pos;
    res.best_dist = center_dist;
  }
  return res;
}
class TournamentTree {
 public:
  TournamentTree(int N) {
    n = 1;
    while (n < N) {
      n <<= 1;
    }
    T.assign(2 * n, Node());
    for (int i = N; i < n; ++i) {
      T[n + i].size = 0;
    }
    for (int i = n - 1; i > 0; --i) {
      T[i] = join(T[2 * i], T[2 * i + 1]);
    }
  }
  void set(int pos) {
    pos += n;
    T[pos].left_car = T[pos].right_car = 0;
    T[pos].best_dist = -1;
    fix_up(pos / 2);
  }
  void clear(int pos) {
    pos += n;
    T[pos].left_car = -inf;
    T[pos].right_car = +inf;
    T[pos].best_dist = 0;
    fix_up(pos / 2);
  }
  int query() const {
    const Node &x = T[1];
    int ret = x.best_pos;
    int best = x.best_dist;
    if (x.left_car == -inf) {
      assert(x.right_car == +inf);
      return 0;
    }
    assert(x.right_car < +inf);
    if (x.left_car - 1 >= best) {
      ret = 0;
      best = x.left_car - 1;
    }
    if (x.size - x.right_car - 2 > best) {
      ret = x.size - 1;
      best = x.size - x.right_car - 2;
    }
    return ret;
  }

 private:
  int n;
  vector<Node> T;
  void fix_up(int node) {
    while (node > 0) {
      T[node] = join(T[2 * node], T[2 * node + 1]);
      node /= 2;
    }
  }
};
int pos[1000000];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  TournamentTree T(n);
  for (int i = 0; i < m; ++i) {
    int type, k;
    scanf("%d %d", &type, &k);
    if (type == 1) {
      int sol = T.query();
      T.set(sol);
      pos[k - 1] = sol;
      printf("%d\n", sol + 1);
    } else {
      T.clear(pos[k - 1]);
    }
  }
  return 0;
}