#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n,m,sum[1000010],flag[1000010],len[1000010];
void pushup(int o)
{
sum[o] = sum[o * 2] + sum[o * 2 + 1];
}
void build(int l,int r,int o)
{
len[o] = r - l + 1;
if (l == r)
{
flag[o] = 0;
sum[o] = 0;
return;
}
int mid = (l + r) >> 1;
build(l,mid,o * 2);
build(mid + 1,r,o * 2 + 1);
pushup(o);
return;
}
void pushdown(int o)
{
if (flag[o])
{
flag[o * 2] ^= 1;
flag[o * 2 + 1] ^= 1;
flag[o] = 0;
sum[o * 2] = len[o * 2] - sum[o * 2];
sum[o * 2 + 1] = len[o * 2 + 1] - sum[o * 2 + 1];
}
}
void update(int l,int r,int o,int x,int y)
{
if (x <= l && r <= y)
{
sum[o] = len[o] - sum[o];
flag[o] ^= 1;
return;
}
pushdown(o);
int mid = (l + r) >> 1;
if (x <= mid)
update(l,mid,o * 2,x,y);
if (y > mid)
update(mid + 1,r,o * 2 + 1,x,y);
pushup(o);
}
int query(int l,int r,int o,int x,int y)
{
if (x <= l && r <= y)
return sum[o];
pushdown(o);
int mid = (l + r) >> 1,cnt = 0;
if (x <= mid)
cnt += query(l,mid,o * 2,x,y);
if (y > mid)
cnt += query(mid + 1,r,o * 2 + 1,x,y);
return cnt;
}
int main()
{
scanf("%d%d",&n,&m);
build(1,n,1);
for (int i = 1; i <= m; i++)
{
int op,s,e;
scanf("%d%d%d",&op,&s,&e);
if (op == 0)
update(1,n,1,s,e);
else
printf("%d\n",query(1,n,1,s,e));
}
return 0;
}