/*
written by- Piyush Golani
language- c++
country- India
College- N.I.T Jamshedpur
*/
#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<map>
#include<queue>
#include<cctype>
using namespace std;
#define pb push_back
#define all(s) s.begin(),s.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define F(i,a,b) for(int i=a;i>=b;i--)
#define PI 3.1415926535897932384626433832795
#define INF 2000000000
#define BIG_INF 7000000000000000000LL
#define mp make_pair
#define eps 1e-9
#define LL long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define mod 1000000007
#define mm 10000000
string inttostring(int n)
{
stringstream a;
a<<n;
return a.str();
}
int stringtoint(string A)
{
istringstream a(A);
int p;
a>>p;
return p;
}
///////////////////////////////////////////////////
int A[9999999];
int flag[9999999];
int update(int node, int ri, int rj, int i, int j)
{
if(i==ri && j==rj) {
flag[node]^= 1;
A[node]= rj-ri +1-A[node];
return 0;
}
int m = (ri + rj)/2;
if(j <= m) update(2*node, ri, m, i, j);
else if(i > m) update(2*node+1, m+1, rj, i, j);
else {
update(2*node, ri, m, i, m);
update(2*node+1, m+1, rj, m+1, j);
}
if(flag[node]) A[node]= rj-ri+1-A[2*node]-A[2*node+1];
else A[node]=A[2*node]+A[2*node+1];
return 0;
}
int query(int node, int ri, int rj, int i, int j) {
if(i==ri && j==rj) return A[node];
int m = (ri + rj)/2;
int ret;
if(j <= m) ret = query(2*node, ri, m, i, j);
else if(i > m) ret = query(2*node+1, m+1, rj, i, j);
else {
ret = query(2*node, ri, m, i, m);
ret += query(2*node+1, m+1, rj, m+1, j);
}
if(flag[node]) return j-i+1-ret;
return ret;
}
int main()
{
int N;
si(N);
int Q;
si(Q);
int a,Aa,B;
while(Q--)
{
si(a); si(Aa); si(B);
if(a==0)
{
update(1,0,N-1,Aa,B);
}
else
{
int t=query(1,0,N-1,Aa,B);
printf("%d\n",t);
}
//cout<<A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WxzZSBpZihpID4gbSkgcmV0ID0gcXVlcnkoMipub2RlKzEsIG0rMSwgcmosIGksIGopOwoJZWxzZSB7CgkJcmV0ID0gcXVlcnkoMipub2RlLCByaSwgbSwgaSwgbSk7CgkJcmV0ICs9IHF1ZXJ5KDIqbm9kZSsxLCBtKzEsIHJqLCBtKzEsIGopOwoJfQoJaWYoZmxhZ1tub2RlXSkgcmV0dXJuIGotaSsxLXJldDsKCXJldHVybiByZXQ7Cn0KCgoKaW50IG1haW4oKQp7CiAgICBpbnQgTjsKICAgIHNpKE4pOwogICAgaW50IFE7CiAgICBzaShRKTsKICAgIGludCBhLEFhLEI7CiAgICB3aGlsZShRLS0pCiAgICB7CiAgICAgICAgc2koYSk7IHNpKEFhKTsgc2koQik7CiAgICAgICAgaWYoYT09MCkKICAgICAgICB7CiAgICAgICAgICAgIHVwZGF0ZSgxLDAsTi0xLEFhLEIpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBpbnQgdD1xdWVyeSgxLDAsTi0xLEFhLEIpOwogICAgICAgICAgICBwcmludGYoIiVkXG4iLHQpOwogICAgICAgIH0KICAgICAgICAvL2NvdXQ8PEFbN108PCJcbiI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==