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 inf = (1 << 30);
const int N = 200005;
struct node {
  int l, r, mid;
  int lc, rc, c;
  int s;
} tree[N << 3];
int n, m;
int ID[1000005];
void up(int id) {
  tree[id].s = tree[id * 2].s + tree[id * 2 + 1].s;
  tree[id].lc = tree[id * 2].lc;
  if (tree[id].lc == tree[id * 2].r - tree[id * 2].l + 1)
    tree[id].lc += tree[id * 2 + 1].lc;
  tree[id].rc = tree[id * 2 + 1].rc;
  if (tree[id].rc == tree[id * 2 + 1].r - tree[id * 2 + 1].l + 1)
    tree[id].rc += tree[id * 2].rc;
  tree[id].c = max(tree[id * 2].c, tree[id * 2 + 1].c);
  tree[id].c = max(tree[id].c, tree[id].lc);
  tree[id].c = max(tree[id].c, tree[id].rc);
  tree[id].c = max(tree[id].c, tree[id * 2].rc + tree[id * 2 + 1].lc);
}
void build(int l, int r, int id) {
  tree[id].l = l;
  tree[id].r = r;
  tree[id].mid = (l + r) >> 1;
  tree[id].s = 0;
  tree[id].lc = tree[id].rc = tree[id].c = (r - l + 1);
  if (l == r) return;
  int mid = tree[id].mid;
  build(l, mid, id * 2);
  build(mid + 1, r, id * 2 + 1);
}
int find1(int id) {
  if (tree[id].l == tree[id].r) {
    return tree[id].l;
  }
  if (tree[id * 2].s)
    return find1(id * 2);
  else
    return find1(id * 2 + 1);
}
int find2(int id) {
  if (tree[id].l == tree[id].r) {
    return tree[id].l;
  }
  if (tree[id * 2 + 1].s)
    return find2(id * 2 + 1);
  else
    return find2(id * 2);
}
int cnt;
int find3(int id) {
  if (tree[id].l == tree[id].r) {
    cnt = 1;
    return tree[id].l;
  }
  if (((tree[id].c + 1) >> 1) == ((tree[id * 2].c + 1) >> 1))
    return find3(id * 2);
  else if (((tree[id].c + 1) >> 1) ==
           ((tree[id * 2].rc + tree[id * 2 + 1].lc + 1) >> 1)) {
    cnt = (tree[id].c + 1) / 2;
    if (cnt <= tree[id * 2].rc) {
      return tree[id * 2].r - tree[id * 2].rc + cnt;
    } else {
      return tree[id * 2 + 1].l - 1 + (cnt - tree[id * 2].rc);
    }
  } else
    return find3(id * 2 + 1);
}
void update(int pos, int id, int c) {
  if (tree[id].l == tree[id].r) {
    tree[id].s += c;
    tree[id].lc = tree[id].rc = tree[id].c = (tree[id].s ^ 1);
    return;
  }
  int mid = tree[id].mid;
  if (pos <= mid)
    update(pos, id * 2, c);
  else
    update(pos, id * 2 + 1, c);
  up(id);
}
int main() {
  int i, j, t, cas = 0;
  int a, b;
  bool flg1, flg2;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  flg1 = flg2 = 0;
  int num = 0;
  while (m--) {
    scanf("%d%d", &a, &b);
    if (a == 1) {
      if (num == 0) {
        ID[b] = 1;
        flg1 = 1;
        update(ID[b], 1, 1);
      } else {
        int f1 = -1, f2 = -1;
        ID[b] = find3(1);
        if (flg1 == 0) f1 = find1(1);
        if (flg2 == 0) f2 = find2(1);
        if (f1 != -1) {
          if (f1 - 1 >= cnt) {
            ID[b] = 1;
            cnt = f1 - 1;
          }
        }
        if (f2 != -1) {
          if (n - f2 > cnt) {
            ID[b] = n;
            cnt = n - f2;
          }
        }
        if (ID[b] == 1)
          flg1 = 1;
        else if (ID[b] == n)
          flg2 = 1;
        update(ID[b], 1, 1);
      }
      printf("%d\n", ID[b]);
      num++;
    } else {
      update(ID[b], 1, -1);
      if (ID[b] == 1) flg1 = 0;
      if (ID[b] == n) flg2 = 0;
      num--;
    }
  }
  return 0;
}