#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define TLE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define maxn 1000500
using namespace std;
int op,a,b;
struct node{
int l,r,dat,add;
}tree[1000001];
int n,m;
void build(int p,int l,int r){
tree[p].l=l;
tree[p].r=r;
if(l==r){
tree[p].dat=0;
return;
}
int mid=(tree[p].l+tree[p].r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
//tree[p].dat=tree[p*2].dat+tree[p*2+1].dat;
}
void down (int p){
if(tree[p].add=0) return;
tree[p*2].dat=tree[p*2].r-tree[p*2].l+1-tree[p*2].dat;
tree[p*2+1].dat=tree[p*2+1].r-tree[p*2+1].l+1-tree[p*2+1].dat;
tree[p*2].add=1-tree[p*2].add;
tree[p*2+1].add=1-tree[p*2+1].add;
tree[p].add=0;
}
void modify(int p,int l,int r){
if(tree[p].l>=l&&tree[p].r<=r){
tree[p].dat=tree[p].r-tree[p].l+1-tree[p].dat;
tree[p].add=1-tree[p].add;
return;
}
down(p);
int mid=(tree[p].l+tree[p].r)/2;
if(a<=mid) modify(p*2,l,r);
if(b>mid) modify(p*2+1,l,r);
tree[p].dat=tree[p*2].dat+tree[p*2+1].dat;
}
int ask(int p,int l,int r){
if(tree[p].l>=l&&tree[p].r<=r)return tree[p].dat;
down(p);
int ans=0;
int mid=(tree[p].l+tree[p].r)/2;
if(a<=mid)ans+=ask(p*2,l,r);
if(b>mid)ans+=ask(p*2+1,l,r);
return ans;
}
int main(){
TLE;
cin>>n>>m;
build(1,1,n);
while(m--){
cin>>op>>a>>b;
if(op==0){
modify(1,a,b);
}
else{
cout<<ask(1,a,b)<<'\n';
}
}
return 0;
}