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 sum[200010 << 2];
int visit[200010 << 2];
int car[200010 * 5];
int v[200010 << 2];
void Push(int N) {
  sum[N << 1] = sum[N << 1 | 1] = 0;
  v[N << 1] = v[N << 1 | 1] = v[N];
  v[N] = 0;
}
int query_x(int l, int r, int N) {
  if (l == r) {
    visit[N] = 1;
    sum[N] = 0;
    return l;
  }
  int mid = (l + r) >> 1, ret;
  if (v[N]) Push(N);
  if (sum[N] == sum[N << 1])
    ret = query_x(l, mid, N << 1);
  else
    ret = query_x(mid + 1, r, N << 1 | 1);
  visit[N] = visit[N << 1] + visit[N << 1 | 1];
  sum[N] = max(sum[N << 1], sum[N << 1 | 1]);
  return ret;
}
int query_v(int P, int l, int r, int N) {
  if (l == r) return visit[N];
  int mid = (l + r) >> 1, ret;
  if (P <= mid)
    ret = query_v(P, l, mid, N << 1);
  else {
    ret = query_v(P, mid + 1, r, N << 1 | 1);
    ret += visit[N << 1];
  }
  return ret;
}
int query_y(int P, int l, int r, int N) {
  if (l == r) return l;
  int mid = (l + r) >> 1, ret;
  if (P <= visit[N << 1])
    ret = query_y(P, l, mid, N << 1);
  else
    ret = query_y(P - visit[N << 1], mid + 1, r, N << 1 | 1);
  return ret;
}
void Update(int P, int l, int r, int N, int num) {
  if (l == r) {
    sum[N] = num;
    return;
  }
  int mid = (l + r) >> 1;
  if (v[N]) Push(N);
  if (P <= mid)
    Update(P, l, mid, N << 1, num);
  else
    Update(P, mid + 1, r, N << 1 | 1, num);
  sum[N] = max(sum[N << 1], sum[N << 1 | 1]);
}
void Up(int L, int R, int l, int r, int N) {
  if (L <= l && r <= R) {
    v[N] = 1;
    sum[N] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (v[N]) Push(N);
  if (L <= mid) Up(L, R, l, mid, N << 1);
  if (mid < R) Up(L, R, mid + 1, r, N << 1 | 1);
  sum[N] = max(sum[N << 1], sum[N << 1 | 1]);
}
void Delet(int P, int l, int r, int N) {
  if (l == r) {
    visit[N] = 0;
    sum[N] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (P <= mid)
    Delet(P, l, mid, N << 1);
  else
    Delet(P, mid + 1, r, N << 1 | 1);
  visit[N] = visit[N << 1] + visit[N << 1 | 1];
  sum[N] = max(sum[N << 1], sum[N << 1 | 1]);
}
void Build1(int l, int r, int N) {
  if (l == r) {
    cout << visit[N];
    return;
  }
  int mid = (l + r) >> 1;
  Build1(l, mid, N << 1);
  Build1(mid + 1, r, N << 1 | 1);
}
void Build2(int l, int r, int N) {
  if (l == r) {
    cout << sum[N];
    return;
  }
  int mid = (l + r) >> 1;
  Build2(l, mid, N << 1);
  Build2(mid + 1, r, N << 1 | 1);
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  memset(sum, 0, sizeof(sum));
  memset(visit, 0, sizeof(visit));
  memset(v, 0, sizeof(v));
  int check, num;
  while (M--) {
    scanf("%d%d", &check, &num);
    if (check == 1) {
      int x = query_x(1, N, 1);
      car[num] = x;
      printf("%d\n", x);
      int k = query_v(x, 1, N, 1);
      if (k < visit[1]) {
        int k1 = query_y(k + 1, 1, N, 1);
        int y = (k1 + x) >> 1;
        Up(x, k1, 1, N, 1);
        Update(y, 1, N, 1, (k1 - x) >> 1);
      } else {
        Up(x, N, 1, N, 1);
        Update(N, 1, N, 1, N - x);
      }
      if (k > 1) {
        int k1 = query_y(k - 1, 1, N, 1);
        int y = (k1 + x) >> 1;
        Up(k1, x, 1, N, 1);
        Update(y, 1, N, 1, (x - k1) >> 1);
      } else {
        Up(1, x, 1, N, 1);
        Update(1, 1, N, 1, x - 1);
      }
    } else if (check == 2) {
      int k = query_v(car[num], 1, N, 1);
      int k1, k2;
      if (k != 1)
        k1 = query_y(k - 1, 1, N, 1);
      else
        k1 = 0;
      if (k != visit[1])
        k2 = query_y(k + 1, 1, N, 1);
      else
        k2 = N + 1;
      Delet(car[num], 1, N, 1);
      if (k1 == 0 && k2 == N + 1) {
        Up(1, N, 1, N, 1);
        Update(1, 1, N, 1, N);
      } else if (k1 == 0) {
        Up(1, k2, 1, N, 1);
        Update(1, 1, N, 1, k2 - 1);
      } else if (k2 == N + 1) {
        Up(k1, N, 1, N, 1);
        Update(N, 1, N, 1, N - k1);
      } else {
        Up(k1, k2, 1, N, 1);
        Update((k1 + k2) >> 1, 1, N, 1, (k2 - k1) >> 1);
      }
    }
  }
  return 0;
}