#include<iostream>
#define lc p << 1
#define rc p << 1 | 1
using namespace std;
const int N = 2e5 + 10;
struct Node {
int l, r;
int sum;
int tag;
}node[N<<2];
int n, m;
void push_up(int p)
{
node[p].sum = node[lc].sum + node[rc].sum;
}
void build(int p, int r, int l)
{
node[p].l = l, node[p].r = r, node[p].sum = 0, node[p].tag = 0;
if (l == r) {
return;
}
int mid = l + r >> 1;
build(lc, l, mid);
build(rc, mid + 1, r);
}
void push_down(int p) {
if (node[p].tag) {
node[lc].sum = node[lc].r - node[lc].l + 1 - node[lc].sum;
node[rc].sum = node[rc].r - node[rc].l + 1 - node[rc].sum;
node[lc].tag = (node[lc].tag == 1 ? 0 : 1);
node[rc].tag = (node[rc].tag == 1 ? 0 : 1);
node[p].tag = 0;
}
}
void action(int p, int x, int y)
{
if (node[p].r <= y && node[p].l >= x) {
node[p].sum = node[p].r - node[p].l + 1 - node[p].sum;
node[p].tag = (node[p].tag == 1 ? 0 : 1);
return;
}
push_down(p);
int mid = node[p].r + node[p].l >> 1;
if (x <= mid) action(lc, x, y);
if (y > mid) action(rc, x, y);
push_up(p);
}
int query(int p, int x, int y) {
if (node[p].l >= x && node[p].r <= y) {
return node[p].sum;
}
int tmp = 0;
push_down(p);
int mid = node[p].l + node[p].r >> 1;
if (x <= mid) tmp += query(lc, x, y);
if (y > mid) tmp += query(rc, x, y);
return tmp;
}
int main()
{
cin >> n >> m;
build(1, 1, n);
for (int i = 0; i < m; i++) {
int c = 0;
cin >> c;
if (c == 0) {
int x, y;
cin >> x >> y;
action(1, x, y);
}
else if (c == 1) {
int x, y;
cin >> x >> y;
int ans = query(1, x, y);
cout << ans << '\n';
}
}
return 0;
}