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;
typedef struct node {
  int ini, fim;
  int lb, rb;
  int dist, pos;
} node;
typedef struct cell {
  int esq, dir;
} cell;
int n, where[10 * 200010];
cell tree[3 * 200010];
set<node> myset;
set<node>::iterator it;
bool operator<(node a, node b) {
  if (a.dist == b.dist) return a.pos < b.pos;
  return a.dist > b.dist;
}
void imprime(node e) {
  printf("ini (%d)%d fim %d(%d) dist %d pos %d\n", e.lb, e.ini, e.fim, e.rb,
         e.dist, e.pos);
}
void calc(node *e) {
  int l, r, dist, pos;
  e->lb = e->rb = 1;
  if (e->ini == 0) e->lb = 0;
  if (e->fim == n - 1) e->rb = 0;
  l = e->lb;
  r = e->rb;
  if (!l && !r) {
    dist = e->fim - e->ini + 2;
    pos = e->ini;
  } else if (!l && r) {
    dist = e->fim - e->ini + 1;
    pos = e->ini;
  } else if (l && !r) {
    dist = e->fim - e->ini + 1;
    pos = e->fim;
  } else {
    dist = (e->fim - e->ini + 2) / 2;
    pos = e->ini + dist - 1;
  }
  e->dist = dist;
  e->pos = pos;
  return;
}
void build(int v, int b, int e) {
  tree[v].esq = -1;
  tree[v].dir = n;
  if (b == e) return;
  int m = (b + e) / 2;
  build(2 * v + 1, b, m);
  build(2 * v + 2, m + 1, e);
  return;
}
cell update(int v, int b, int e, int pos, int val) {
  if (b > pos || e < pos) return tree[v];
  if (b == e && b == pos) {
    if (val) {
      tree[v].esq = tree[v].dir = b;
    } else {
      tree[v].esq = -1;
      tree[v].dir = n;
    }
    return tree[v];
  }
  int m = (b + e) / 2;
  cell p, q;
  p = update(2 * v + 1, b, m, pos, val);
  q = update(2 * v + 2, m + 1, e, pos, val);
  tree[v].esq = max(p.esq, q.esq);
  tree[v].dir = min(p.dir, q.dir);
  return tree[v];
}
int query_esq(int v, int b, int e, int i, int j) {
  if (b > j || e < i) return -1;
  if (i <= b && e <= j) return tree[v].esq;
  int m = (b + e) / 2;
  return max(query_esq(2 * v + 1, b, m, i, j),
             query_esq(2 * v + 2, m + 1, e, i, j));
}
int query_dir(int v, int b, int e, int i, int j) {
  if (b > j || e < i) return n;
  if (i <= b && e <= j) return tree[v].dir;
  int m = (b + e) / 2;
  return min(query_dir(2 * v + 1, b, m, i, j),
             query_dir(2 * v + 2, m + 1, e, i, j));
}
int main() {
  int Q;
  int t, id, pos, a, b;
  node e, aux;
  scanf("%d%d", &n, &Q);
  build(0, 0, n - 1);
  e.ini = 0;
  e.fim = n - 1;
  calc(&e);
  myset.insert(e);
  while (Q--) {
    scanf("%d%d", &t, &id);
    if (t == 1) {
      it = myset.begin();
      e = *it;
      myset.erase(it);
      pos = e.pos;
      update(0, 0, n - 1, pos, 1);
      if (e.fim - pos > 0) {
        aux.ini = pos + 1;
        aux.fim = e.fim;
        calc(&aux);
        myset.insert(aux);
      }
      if (pos - e.ini > 0) {
        aux.ini = e.ini;
        aux.fim = pos - 1;
        calc(&aux);
        myset.insert(aux);
      }
      where[id] = pos;
      printf("%d\n", pos + 1);
    } else {
      pos = where[id];
      a = query_esq(0, 0, n - 1, 0, pos - 1);
      b = query_dir(0, 0, n - 1, pos + 1, n - 1);
      update(0, 0, n - 1, pos, 0);
      if (pos - a - 1 > 0) {
        aux.ini = a + 1;
        aux.fim = pos - 1;
        calc(&aux);
        myset.erase(aux);
      }
      if (b - pos - 1 > 0) {
        aux.ini = pos + 1;
        aux.fim = b - 1;
        calc(&aux);
        myset.erase(aux);
      }
      aux.ini = a + 1;
      aux.fim = b - 1;
      calc(&aux);
      myset.insert(aux);
    }
  }
  return 0;
}