#include <bits/stdc++.h>
using namespace std;
int n, t[100005];
void inc(int x, int v) {
  for (; x <= n; x += x & -x) t[x] += v;
}
int que(int x) {
  int z = 0;
  for (; x; x -= x & -x) z += t[x];
  return z;
}
int main() {
  ios::sync_with_stdio(false);
  int q, o, p, l, r;
  bool b = 0;
  cin >> n >> q;
  int x = 0, y = n;
  for (int i = 1; i <= n; i++) inc(i, 1);
  while (q--) {
    cin >> o;
    if (o == 1) {
      cin >> p;
      if (p + p > y - x) {
        p = y - x - p;
        b = !b;
      }
      if (!b) {
        for (int i = x + 1; i <= x + p; i++) {
          int w = que(i) - que(i - 1);
          inc(x + x + p + p - i + 1, w);
        }
        x += p;
      } else {
        for (int i = y; i > y - p; i--) {
          int w = que(i) - que(i - 1);
          inc(y + y - p - p - i + 1, w);
        }
        y -= p;
      }
    } else {
      cin >> l >> r;
      if (b) {
        cout << que(y - l) - que(y - r) << '\n';
      } else {
        cout << que(x + r) - que(x + l) << '\n';
      }
    }
  }
}
