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 JAVA):

Solution:


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class ProblemE_135 implements Runnable{
	
	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");
	
	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}
	
	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}
		return tok.nextToken();
	}
	
	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}
	
	long readLong() throws IOException{
		return Long.parseLong(readString());
	}
	
	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}
	
	public static void main(String[] args){
		new Thread(null, new ProblemE_135(), "", 128 * (1L << 20)).start();
	}
	
	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}
	
	long memoryTotal, memoryFree;
	

	void memory(){
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}
	
	void debug(Object... objects){
		if (DEBUG){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}
	
	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			time();
			memory();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}
	
	class Segment implements Comparable<Segment>{
		int left, right;
		int best, d;
		public Segment(int left, int right) {
			super();
			this.left = left;
			this.right = right;
			
			this.best = (right + left) / 2;
			best = max(best, 1);
			best = min(best, n);
			this.d = (min(best - left, right - best));
		}
		@Override
		public int compareTo(Segment s) {
			if (d > s.d) return -1;
			if (d < s.d) return 1;
			return left - s.left;
		}
	}
	
	boolean DEBUG = false;
	
	int n;
	
	Map<Integer, Integer> pos, next, prev;
	PriorityQueue<Segment> q;
	
	void solve() throws IOException{
		n = readInt();
		pos = new HashMap<Integer, Integer>();
		
		prev = new HashMap<Integer, Integer>();
		prev.put(1, Integer.MIN_VALUE / 2);
		
		next = new HashMap<Integer, Integer>();
		next.put(n, Integer.MAX_VALUE / 2);
		
		q = new PriorityQueue<Segment>();
		addSegment(prev.get(1), next.get(n));
		
		int m = readInt();
		while (m-- > 0){
			int op = readInt();
			int id = readInt();
			
			if (op == 1){
				Segment s = q.poll();
				
				while (!check(s)){
					s = q.poll();
				}
				
				out.println(s.best);
				
				addSegment(s.left, s.best);
				addSegment(s.best, s.right);
				pos.put(id, s.best);
			}else{
				removeCar(id);
			}
		}
	}
	
	void addSegment(int left, int right){
		prev.put(right, left);
		next.put(left, right);
		
		q.add(new Segment(left, right));
	}
	
	boolean check(Segment s){
		Integer left = prev.get(s.right);
		Integer right = next.get(s.left);
		
		if (left == null || right == null) return false;
		
		return (left == s.left && s.right == right);
	}
	
	void removeCar(int id){
		Integer carPlace = pos.get(id);
		pos.remove(id);
		
		addSegment(prev.get(carPlace), next.get(carPlace));
		
		prev.remove(carPlace);
		next.remove(carPlace);
	}
}