#include<fstream>
#include<iostream>
#include<vector>
#include<set>
using namespace std;
void display_set(multiset<int> &free) {
for (auto it = free.begin(); it != free.end(); ++it) {
cout << *it << " ";
}
cout << "\n";
return;
}
void delete_interval(multiset<int> &free, int a, int b) {
//[a, b)
int l = b - a;
auto it = free.find(l);
if (it != free.end())
free.erase(it);
else
cout << "something went wrong \n";
}
void add_interval(multiset<int> &free, int a, int b) {
//[a, b)
int l = b - a;
free.insert(l);
}
void add_interval(set <pair <int, int>> &busy, multiset <int> &free, int a, int b) {
auto after = busy.upper_bound({b, 0});
auto before = after;
before--;
delete_interval(free, before->second, after->first);
if (a == before->second && b == after->first) {
busy.erase(before);
busy.erase(after);
busy.insert({before->first, after->second});
} else if (a == before->second) {
busy.erase(before);
busy.insert({before->first, b});
add_interval(free, b, after->first);
} else if (b == after->first) {
busy.erase(after);
busy.insert({a, after->second});
add_interval(free, before->second, a);
} else {
busy.insert({a, b});
add_interval(free, before->second, a);
add_interval(free, b, after->first);
}
return;
}
void remove_interval(set <pair <int, int>> &busy, multiset <int> &free, int a, int b) {
auto after = busy.upper_bound({b, 0});
auto current = after;
current--;
if (a == current->first) {
auto before = current;
before--;
if (b == current->second) {
delete_interval(free, before->second, a);
delete_interval(free, b, after->first);
add_interval(free, before->second, after->first);
} else {
busy.insert({b, current->second});
delete_interval(free, before->second, a);
add_interval(free, before->second, b);
}
} else {
if (b == current->second) {
busy.insert({current->first, a});
delete_interval(free, b, after->first);
add_interval(free, a, after->first);
} else {
busy.insert({current->first, a});
busy.insert({b, current->second});
add_interval(free, a, b);
}
}
busy.erase(current);
return;
}
int main() {
ifstream fin("hotel.in");
ofstream fout("hotel.out");
int n, p; fin >> n >> p;
set <pair <int, int>> busy;
multiset <int> free;
add_interval(free, 1, n + 1);
busy.insert({0, 1});
busy.insert({n + 1, n + 2});
for (int i = 0; i < p; i++) {
int t; fin >> t;
if (t == 3) {
if (free.empty())
fout << "0 \n";
else {
auto big = --free.end();
fout << *big << "\n";
}
} else if (t == 1) {
int a, b; fin >> a >> b;
add_interval(busy, free, a, a + b);
// cout << "after add \n";
// display_set(free);
} else if (t == 2) {
int a, b; fin >> a >> b;
remove_interval(busy, free, a, a + b);
// cout << "after remove \n";
// display_set(free);
}
// display_set(free);
}
return 0;
}