#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
struct Tag {
bool cg;
Tag(bool a) {
cg = a;
}
Tag() {
cg = 0;
}
void aply(const Tag &t) {
cg ^= t.cg;
}
};
struct Info {
int c[2];
void aply(const Tag &t) {
if (t.cg) {
swap(c[0], c[1]);
}
}
};
Info operator+ (const Info &a, const Info &b) {
return {a.c[0] + b.c[0], a.c[1] + b.c[1]};
}
struct SegmentTree {
int n;
vector<Info> s;
vector<Tag> t; // sum, tag
SegmentTree(int n_, vector<Info> init) {
n = n_;
s.assign(n * 4 + 1, Info());
t.assign(n * 4 + 1, Tag());
build(1, 1, n, init);
}
void push_up(int u) {
s[u] = s[u * 2] + s[u * 2 + 1];
}
void build(int u, int l, int r, vector<Info> &init) {
if (l == r) {
s[u] = init[l];
return;
}
int mid = l + r >> 1;
build(u * 2, l, mid, init);
build(u * 2 + 1, mid + 1, r, init);
push_up(u);
}
void aply(int u, const Tag &tag) {
t[u].aply(tag);
s[u].aply(tag);
}
void push_down(int u) {
aply(u * 2, t[u]);
aply(u * 2 + 1, t[u]);
t[u] = Tag();
}
Info query(int u, int l, int r, int x, int y) {
if (x <= l && y >= r) return s[u];
push_down(u);
int mid = l + r >> 1;
Info sum = Info();
if (x <= mid) sum = sum + query(u * 2, l, mid, x, y);
if (y > mid) sum = sum + query(u * 2 + 1, mid + 1, r, x, y);
return sum;
}
Info query(int l, int r) {
return query(1, 1, n, l, r);
}
void change(int u, int l, int r, int x, int y, const Tag &tag) {
if (x <= l && y >= r) {
aply(u, tag);
return;
}
push_down(u);
int mid = l + r >> 1;
if (x <= mid) change(u * 2, l, mid, x, y, tag);
if (y > mid) change(u * 2 + 1, mid + 1, r, x, y, tag);
push_up(u);
}
void change(int l, int r, const Tag &v) {
change(1, 1, n, l, r, v);
}
};
void solve() {
int n, m;
cin >> n >> m;
vector<Info> a(n + 1);
for (int i = 1; i <= n; i++) a[i].c[0] = 1;
SegmentTree t(n, a);
while (m--) {
ll o, x, y, v;
cin >> o >> x >> y;
if (o == 1) {
cout << t.query(x, y).c[1] << '\n';
} else {
t.change(x, y, Tag(1));
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
/*
g++ -std=c++20 1.cpp -o 1 && 1 < in.txt > out.txt
*/