/*
ZADATAK: atomi
JEZIK: c++
*/

// Atomi, SIO 2007
// Autor zadatka : Rajko Nenadov

/*
resenje nosi : 100 poena
vremenska slozenost : O(M * log N)
prostorna slozenost : O(N)
*/

#include <iostream>
#include <cstdio>
using namespace std;

const long MaxN = 1048576; // 2^20
const long MaxTree = MaxN * 2 + 1;

struct Cvor{
    long levo, desno, najveci;
    bool ceo;
};

Cvor tree[MaxTree], aux_tree[MaxTree];
long n, upper_n;
long m;

FILE *fin, *fout;

void make_tree(){
    for (long i=0; i<MaxTree; i++){
        tree[i].levo = 0; tree[i].desno = 0; tree[i].najveci = 0;
        tree[i].ceo = false;
    }
}

void update(long x){
    while (x>=1){
        long L1 = tree[2*x].levo, D1 = tree[2*x].desno, N1 = tree[2*x].najveci;
        bool C1 = tree[2*x].ceo;
        long L2 = tree[2*x + 1].levo, D2 = tree[2*x + 1].desno, N2 = tree[2*x + 1].najveci;
        bool C2 = tree[2*x + 1].ceo;

        if (C1) tree[x].levo = L1 + L2;
        else tree[x].levo = L1;

        if (C2) tree[x].desno = D2 + D1;
        else tree[x].desno = D2;

        tree[x].najveci = max(max(N1,N2), D1 + L2);

        tree[x].ceo = C1 && C2;

        x/=2;
    }
}

void dodaj(long x){
    tree[x].levo = 1; tree[x].desno = 1; tree[x].najveci = 1;
    tree[x].ceo = true;
    update(x/2);
}

void izbaci(long x){
    tree[x].levo = 0; tree[x].desno = 0;  tree[x].najveci = 0;
    tree[x].ceo = false;
    update(x/2);
}

void query(long ind, long p, long q, long a, long b){
    if (a<=p && q<=b){
        aux_tree[ind] = tree[ind];
    }
    else if (a>q ||p>b){
        aux_tree[ind].levo = 0; aux_tree[ind].desno = 0; aux_tree[ind].najveci = 0;
        aux_tree[ind].ceo = false;
    }
    else{
        query(ind*2, p, (p+q)/2, a, b);
        query(ind*2 + 1, (p+q)/2 + 1, q, a, b);

        long L1 = aux_tree[2*ind].levo, D1 = aux_tree[2*ind].desno, N1 = aux_tree[2*ind].najveci;
        bool C1 = aux_tree[2*ind].ceo;
        long L2 = aux_tree[2*ind + 1].levo, D2 = aux_tree[2*ind + 1].desno, N2 = aux_tree[2*ind + 1].najveci;
        bool C2 = aux_tree[2*ind + 1].ceo;

        if (C1) aux_tree[ind].levo = L1 + L2;
        else aux_tree[ind].levo = L1;

        if (C2) aux_tree[ind].desno = D2 + D1;
        else aux_tree[ind].desno = D2;

        aux_tree[ind].najveci = max(max(N1,N2), D1 + L2);

        aux_tree[ind].ceo = C1 && C2;
    }
}

int main(){
    fin=fopen("atomi.in","r");
    fout=fopen("atomi.out","w");

    fscanf(fin,"%ld %ld",&n,&m);
    upper_n = 1;
    while (upper_n<n) upper_n*=2;

    make_tree();
    long op,x,a,b;

    for (long k=0; k<m; k++){
        fscanf(fin,"%ld",&op);
        if (op == 0){
            fscanf(fin,"%ld",&x);
            izbaci(upper_n+x-1);
        }
        else if (op == 1){
            fscanf(fin,"%ld",&x);
            dodaj(upper_n+x-1);
        }
        else{
            fscanf(fin,"%ld %ld",&a,&b);
            query(1,1,upper_n,a,b);
            fprintf(fout,"%ld\n",aux_tree[1].najveci);
        }
    }

    fclose(fin); fclose(fout);
    return 0;
}

