#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
ifstream fin( "hotel.in" );
ofstream fout( "hotel.out" );
struct Node{
int maxLen;
int prefMax, sufMax;
int lazy; // 1 - deschise toate, 2 - inchise toate
};
Node aint[2*MAXN+1];
void compute( int node, int leftSon, int rightSon, int left, int right, int mid ) {
if( aint[leftSon].prefMax == mid - left + 1 )
aint[node].prefMax = aint[leftSon].prefMax + aint[rightSon].prefMax;
else
aint[node].prefMax = aint[leftSon].prefMax;
if( aint[rightSon].sufMax == right - mid )
aint[node].sufMax = aint[rightSon].sufMax + aint[leftSon].sufMax;
else
aint[node].sufMax = aint[rightSon].sufMax;
aint[node].maxLen = max( max( aint[leftSon].maxLen, aint[rightSon].maxLen ), aint[leftSon].sufMax + aint[rightSon].prefMax );
}
void push( int node, int leftSon, int rightSon, int left, int right, int mid ) {
if( aint[node].lazy == 1 ) {
aint[node].lazy = 0;
aint[leftSon].maxLen = aint[leftSon].prefMax = aint[leftSon].sufMax = mid - left + 1;
aint[rightSon].maxLen = aint[rightSon].prefMax = aint[rightSon].sufMax = right - mid;
aint[leftSon].lazy = aint[rightSon].lazy = 1;
}
else {
aint[node].lazy = 0;
aint[leftSon].maxLen = aint[leftSon].prefMax = aint[leftSon].sufMax = 0;
aint[rightSon].maxLen = aint[rightSon].prefMax = aint[rightSon].sufMax = 0;
aint[leftSon].lazy = aint[rightSon].lazy = 2;
}
}
void build( int node, int left, int right ) {
if( left == right ) {
aint[node] = { 1, 1, 1, 0 };
return;
}
aint[node] = { right - left + 1, right - left + 1, right - left + 1, 0 };
int mid = ( left + right ) / 2;
int leftChild = node + 1;
int rightChild = node + 2 * ( mid - left + 1 );
build( leftChild, left, mid );
build( rightChild, mid + 1, right );
}
void update( int node, int left, int right, int qleft, int qright, int val ) {
if( qleft <= left && right <= qright ) {
aint[node].lazy = val;
if( val == 1 )
aint[node].maxLen = aint[node].prefMax = aint[node].sufMax = right - left + 1;
else
aint[node].maxLen = aint[node].prefMax = aint[node].sufMax = 0;
}
if( left > qright || right < qleft )
return;
if( left == right )
return;
int mid, leftSon, rightSon;
mid = ( left + right ) / 2;
leftSon = node + 1;
rightSon = node + 2 * ( mid - left + 1 );
if( aint[node].lazy && left != right )
push( node, leftSon, rightSon, left, right, mid );
if( qleft <= mid )
update( leftSon, left, mid, qleft, qright, val );
if( qright > mid )
update( rightSon, mid + 1, right, qleft, qright, val );
compute( node, leftSon, rightSon, left, right, mid );
}
int query() {
return aint[1].maxLen;
}
int main() {
int n, m, i, left, nr, right, op;
fin >> n >> m;
build( 1, 1, n );
for( i = 0; i < m; i++ ) {
fin >> op;
if( op == 3 )
fout << query() << "\n";
else {
if( op == 1 )
op = 2;
else
op = 1;
fin >> left >> nr;
right = left + nr - 1;
update( 1, 1, n, left, right, op );
}
}
return 0;
}