시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB286640.000%

문제

Kamila is once again devising a new amazing programming language that will be superior to all other languages in every aspect. Writing code will become even simpler than ABC, so little children will learn how to program before they will know how to write comments. This is not a bug, as comments are absolutely unnecessary in Kamila’s dreamt up language: Due to its intuitive syntax, the purpose of any block of code is immediately crystally clear. Also, the compiler will bake you a cake for your birthday.

There is still a handful of outstanding issues though. For example, the language constructs for memory management do not work yet. Kamila prepared a precise specification of the memory allocation and freeing procedures, but she did not find enough time to implement them. Help her, and achieve instant fame for contributing to such an important project!

The available memory is an array of n bytes numbered 0 through n − 1. At the beginning, all the bytes are free (i.e., not allocated). Then the memory management system allocates and frees the bytes according to a sequence of queries.

An allocation query is specified by an integer ℓ. The system finds a block of ℓ consecutive free bytes, allocates them, and returns the position of the first byte in this block. If there are multiple such blocks available, the one starting at the position with the smallest number is chosen. If there is no such block available, the query is rejected and the system returns −1.

A freeing query is specified by two integers x and ℓ. The system marks the block of ℓ consecutive bytes starting at the position x as free, and returns the number of actually freed bytes (i.e., the number of bytes in this block that were not free before the query).

입력

The first line of the input consists of two integers n and q – the number of bytes in the available memory and the number of queries (1 ≤ n, q ≤ 3 · 105).

Each of the following q lines describes a query. The first integer in a line determines the type of the query: 1 is for allocation and 2 for freeing. A line with an allocation query then continues with one additional integer ℓ (1 ≤ ℓ ≤ n). Similarly, a line with a freeing query continues with two integers x and ℓ (0 ≤ x ≤ n − 1, 1 ≤ ℓ ≤ n − x).

출력

For every query in the given sequence, output one line with the value returned by the system.

예제 입력 1

5 4
1 3
1 3
2 1 3
1 4

예제 출력 1

0
-1
2
1