#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = (1 << 29);
int n, q;
long long c[maxn];
int op, p, l, r;
int lp, rp;
bool flag;
int lowbit(int x) { return x & (-x); }
void add(int p, long long x) {
  while (p <= n) {
    c[p] += x;
    p += lowbit(p);
  }
}
long long sum(int p) {
  long long res = 0;
  while (p > 0) {
    res += c[p];
    p -= lowbit(p);
  }
  return res;
}
int main() {
  while (cin >> n >> q) {
    memset(c, 0, sizeof(c));
    lp = 0;
    rp = n;
    flag = 0;
    for (int i = 1; i <= n; i++) add(i, 1);
    while (q--) {
      scanf("%d", &op);
      if (op == 1) {
        scanf("%d", &p);
        p += lp;
        if (flag) p = lp + rp - p;
        if (p <= (lp + rp) / 2) {
          for (int i = lp + 1; i <= p; i++)
            add(2 * p - i + 1, sum(i) - sum(i - 1));
          lp = p;
          flag = 0;
        } else {
          for (int i = p + 1; i <= rp; i++)
            add(2 * p - i + 1, sum(i) - sum(i - 1));
          rp = p;
          flag = 1;
        }
      } else {
        scanf("%d%d", &l, &r);
        l += lp;
        r += lp;
        if (flag) l = lp + rp - l, r = lp + rp - r, swap(l, r);
        printf("%I64d\n", sum(r) - sum(l));
      }
    }
  }
  return 0;
}
