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;
struct node {
  int l, r, sum;
  int lo, ro, o;
  int st;
  int mid() { return (l + r) >> 1; }
  int dis() { return r - l + 1; }
} a[220000 * 4];
void make(int l, int r, int k) {
  a[k].l = l;
  a[k].r = r;
  a[k].lo = a[k].ro = a[k].o = a[k].dis();
  a[k].st = -1;
  if (l == r) return;
  int md = a[k].mid();
  make(l, md, k << 1);
  make(md + 1, r, (k << 1) + 1);
}
void update(int l, int r, int k, int op) {
  if (a[k].l == l && a[k].r == r) {
    a[k].st = op;
    if (op) {
      a[k].lo = a[k].ro = a[k].o = 0;
    } else {
      a[k].lo = a[k].ro = a[k].o = a[k].dis();
    }
    return;
  }
  if (a[k].st != -1) {
    a[k << 1].st = a[k << 1 | 1].st = a[k].st;
    a[k].st = -1;
    int oo = a[k << 1].st;
    if (oo) {
      a[k << 1].lo = a[k << 1].ro = a[k << 1].o = a[k << 1 | 1].lo =
          a[k << 1 | 1].ro = a[k << 1 | 1].o = 0;
    } else {
      a[k << 1].lo = a[k << 1].ro = a[k << 1].o = a[k << 1].dis();
      a[k << 1 | 1].lo = a[k << 1 | 1].ro = a[k << 1 | 1].o =
          a[k << 1 | 1].dis();
    }
  }
  int md = a[k].mid();
  if (r <= md) {
    update(l, r, k << 1, op);
  } else if (l > md) {
    update(l, r, k << 1 | 1, op);
  } else {
    update(l, md, k << 1, op);
    update(md + 1, r, k << 1 | 1, op);
  }
  a[k].o = max(a[k << 1].o, a[k << 1 | 1].o);
  a[k].o = max(a[k].o, a[k << 1].ro + a[k << 1 | 1].lo);
  a[k].lo = a[k << 1].lo;
  if (a[k << 1].lo == a[k << 1].dis()) {
    a[k].lo += a[k << 1 | 1].lo;
  }
  a[k].ro = a[k << 1 | 1].ro;
  if (a[k << 1 | 1].ro == a[k << 1 | 1].dis()) {
    a[k].ro += a[k << 1].ro;
  }
}
int query(int w, int k) {
  if (a[k].l == a[k].r && w == 1) {
    return a[k].l;
  }
  if (a[k].st != -1) {
    a[k << 1].st = a[k << 1 | 1].st = a[k].st;
    a[k].st = -1;
    int op = a[k << 1].st;
    if (op) {
      a[k << 1].lo = a[k << 1].ro = a[k << 1].o = a[k << 1 | 1].lo =
          a[k << 1 | 1].ro = a[k << 1 | 1].o = 0;
    } else {
      a[k << 1].lo = a[k << 1].ro = a[k << 1].o = a[k << 1].dis();
      a[k << 1 | 1].lo = a[k << 1 | 1].ro = a[k << 1 | 1].o =
          a[k << 1 | 1].dis();
    }
  }
  if (a[k << 1].o >= w) {
    return query(w, k << 1);
  } else if (a[k << 1].ro + a[k << 1 | 1].lo >= w) {
    return a[k << 1].r - a[k << 1].ro + 1;
  } else if (a[k << 1 | 1].o >= w) {
    return query(w, k << 1 | 1);
  } else
    return 0;
}
int idx[1111111];
int main() {
  int i, j, k, n, m;
  set<int> st;
  while (scanf("%d%d", &n, &m) != EOF) {
    make(1, n, 1);
    while (m--) {
      int q;
      scanf("%d", &q);
      if (q == 1) {
        int y;
        scanf("%d", &y);
        int mx = a[1].o;
        int d = (mx - 1) / 2;
        int d1 = -1, d2 = -1;
        if (!st.empty() && *st.begin() != 1 && *st.begin() - 2 >= d) {
          d1 = *st.begin() - 2;
        }
        if (!st.empty() && *st.rbegin() != n && n - *st.rbegin() - 1 > d) {
          d2 = n - *st.rbegin() - 1;
        }
        if (d1 >= d && d1 >= d2) {
          update(1, 1, 1, 1);
          idx[y] = 1;
          st.insert(1);
          puts("1");
          continue;
        }
        if (d2 >= d && d2 > d1) {
          update(n, n, 1, 1);
          idx[y] = n;
          st.insert(n);
          printf("%d\n", n);
          continue;
        }
        int s = query(mx, 1), t = 1200000;
        if (mx % 2 == 0) {
          t = query(mx - 1, 1);
        }
        if (s <= t) {
          if (s == 1) {
            update(1, 1, 1, 1);
            idx[y] = 1;
            st.insert(1);
            puts("1");
            continue;
          }
          if (s + mx - 1 == n) {
            update(n, n, 1, 1);
            idx[y] = n;
            st.insert(n);
            printf("%d\n", n);
            continue;
          }
          int h = (mx + 1) / 2;
          update(s + h - 1, s + h - 1, 1, 1);
          idx[y] = s + h - 1;
          st.insert(s + h - 1);
          printf("%d\n", s + h - 1);
        } else {
          s = t;
          mx--;
          if (s == 1) {
            update(1, 1, 1, 1);
            idx[y] = 1;
            st.insert(1);
            puts("1");
            continue;
          }
          if (s + mx - 1 == n) {
            update(n, n, 1, 1);
            idx[y] = n;
            st.insert(n);
            printf("%d\n", n);
            continue;
          }
          int h = (mx + 1) / 2;
          update(s + h - 1, s + h - 1, 1, 1);
          idx[y] = s + h - 1;
          st.insert(s + h - 1);
          printf("%d\n", s + h - 1);
        }
      } else {
        int y;
        scanf("%d", &y);
        y = idx[y];
        st.erase(y);
        update(y, y, 1, 0);
      }
    }
  }
  return 0;
}