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 MAX = 2e5 + 20;
int n, m;
struct Treap {
  int key;
  int f, maxf, idxl;
  int height, s;
  int l, r;
  Treap *left, *right, *parent;
  Treap(int a, int b, Treap *parent = 0) : l(a), r(b), parent(parent) {
    height = rand();
    s = 1;
    int tmp = r - l + 1;
    if (l == 1 || r == n)
      f = tmp;
    else {
      if (tmp % 2 == 0)
        f = tmp / 2;
      else
        f = tmp / 2 + 1;
    }
    key = l, maxf = f, idxl = l;
    left = right = 0;
  }
  void restore() {
    int tmp = r - l + 1;
    if (tmp % 2 == 0)
      f = tmp / 2;
    else
      f = tmp / 2 + 1;
    key = l, maxf = f, idxl = l;
  }
  void push() { return; }
  void maintain() {
    maxf = f, idxl = l, s = 1;
    if (left) {
      if (maxf < left->maxf) {
        maxf = left->maxf, idxl = left->idxl;
      } else if (maxf == left->maxf) {
        idxl = left->idxl;
      }
      s += left->s;
    }
    if (right) {
      if (maxf < right->maxf) {
        maxf = right->maxf, idxl = right->idxl;
      }
      s += right->s;
    }
  }
};
Treap *merge(Treap *x, Treap *y) {
  if (!x) return y;
  if (!y) return x;
  if (x->height < y->height) {
    x->push();
    x->right = merge(x->right, y);
    if (x->right) x->right->parent = x;
    x->maintain();
    return x;
  } else {
    y->push();
    y->left = merge(x, y->left);
    if (y->left) y->left->parent = y;
    y->maintain();
    return y;
  }
}
Treap *get_left(Treap *x) {
  if (!x) {
    return x;
  }
  if (!x->left) {
    return x;
  }
  x->push();
  return get_left(x->left);
}
Treap *get_right(Treap *x) {
  if (!x) {
    return x;
  }
  if (!x->right) {
    return x;
  }
  x->push();
  return get_right(x->right);
}
Treap *prev(Treap *cur) {
  cur->push();
  if (cur->left) {
    return get_right(cur->left);
  } else {
    Treap *pa = cur->parent, *prev = cur;
    while (pa) {
      if (prev == pa->right)
        break;
      else
        prev = pa, pa = pa->parent;
    }
    return pa;
  }
}
Treap *next(Treap *cur) {
  cur->push();
  if (cur->right) {
    return get_left(cur->right);
  } else {
    Treap *pa = cur->parent, *prev = cur;
    while (pa) {
      if (prev == pa->left)
        break;
      else
        prev = pa, pa = pa->parent;
    }
    return pa;
  }
}
void split(Treap *t, Treap *&l, Treap *&r, int x) {
  if (!t) {
    l = r = 0;
    return;
  }
  t->push();
  if (t->key >= x) {
    split(t->left, l, t->left, x);
    if (t->left) t->left->parent = t;
    if (l) l->parent = 0;
    r = t;
  } else {
    split(t->right, t->right, r, x);
    if (t->right) t->right->parent = t;
    if (r) r->parent = 0;
    l = t;
  }
  t->maintain();
}
Treap *access(Treap *r, int key) {
  if (!r) return r;
  if (r->key == key) return r;
  r->push();
  if (key < r->key)
    return access(r->left, key);
  else
    return access(r->right, key);
}
void insert(Treap *&r, int l1, int r1) {
  Treap *ne = new Treap(l1, r1);
  Treap *t1, *t2;
  split(r, t1, t2, l1);
  r = merge(t1, ne);
  r = merge(r, t2);
}
Treap *remove(Treap *&r, int key) {
  Treap *x = access(r, key);
  if (x) {
    x->push();
    Treap *xx = merge(x->left, x->right);
    if (x->parent == NULL) {
      r = xx;
      if (r) r->parent = 0;
    } else {
      if (x == x->parent->left)
        x->parent->left = xx;
      else
        x->parent->right = xx;
      if (xx) xx->parent = x->parent;
    }
    Treap *tmp = x->parent;
    if (xx) xx->maintain();
    while (tmp) tmp->maintain(), tmp = tmp->parent;
  }
  return x;
}
Treap *root;
unordered_map<int, int> mm;
bool lots[MAX];
int find(int carid) {
  int bestl = root->idxl;
  Treap *ys = access(root, bestl);
  int pos, newl, newr;
  if (ys->l == 1) {
    pos = 1;
    newl = 2, newr = ys->r;
    remove(root, bestl);
    if (newl <= newr) insert(root, newl, newr);
  } else if (ys->r == n) {
    pos = n;
    newl = ys->l, newr = n - 1;
    remove(root, bestl);
    if (newl <= newr) insert(root, newl, newr);
  } else {
    pos = (ys->l + ys->r) / 2;
    remove(root, bestl);
    newl = ys->l, newr = ys->r;
    if (pos - 1 >= newl) insert(root, newl, pos - 1);
    if (pos + 1 <= newr) insert(root, pos + 1, newr);
  }
  lots[pos] = 1;
  return mm[carid] = pos;
}
Treap *accessR(Treap *r, int ri) {
  if (!r) return r;
  if (r->r == ri) return r;
  r->push();
  if (ri < r->r)
    return accessR(r->left, ri);
  else
    return accessR(r->right, ri);
}
void erase(int carid) {
  int pos = mm[carid];
  if (pos == 1) {
    if (pos + 1 > n || lots[pos + 1] == 1) {
      insert(root, 1, 1);
    } else {
      Treap *ff = access(root, 2);
      int l = 1, r = ff->r;
      remove(root, 2);
      insert(root, l, r);
    }
  } else if (pos == n) {
    if (pos - 1 == 0 || lots[pos - 1] == 1) {
      insert(root, n, n);
    } else {
      Treap *ff = accessR(root, pos - 1);
      int l = ff->l, r = n;
      remove(root, ff->l);
      insert(root, l, r);
    }
  } else {
    int prev = pos - 1, nxt = pos + 1;
    if (lots[prev] && lots[nxt]) {
      insert(root, pos, pos);
    } else if (lots[prev]) {
      Treap *ff = access(root, nxt);
      int l = pos, r = ff->r;
      remove(root, ff->l);
      insert(root, l, r);
    } else if (lots[nxt]) {
      Treap *ff = accessR(root, prev);
      int l = ff->l, r = pos;
      remove(root, ff->l);
      insert(root, l, r);
    } else {
      Treap *fl = accessR(root, prev), *fr = access(root, nxt);
      int l = fl->l, r = fr->r;
      remove(root, fl->l), remove(root, fr->l);
      insert(root, l, r);
    }
  }
  lots[pos] = 0;
}
void dfs(Treap *v, int depth) {
  if (!v) return;
  dfs(v->left, depth + 1);
  for (int i = 0; i < depth; i++) putchar(' ');
  printf("key=%d, s = %d\n", v->key, v->s);
  dfs(v->right, depth + 1);
}
void print(void *p) { dfs((Treap *)p, 0); }
int main() {
  scanf("%d%d", &n, &m);
  memset(lots, 0, sizeof(lots));
  root = 0;
  insert(root, 1, n);
  while (m--) {
    int t, cid;
    scanf("%d%d", &t, &cid);
    if (t == 1) {
      printf("%d\n", find(cid));
    } else {
      erase(cid);
    }
  }
  return 0;
}