#include <bits/stdc++.h>
using namespace std;
int n, q;
int start;
int le, ri;
int dir;
int t[1000000];
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr)
    t[v] += val;
  else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2, tl, tm, pos, val);
    else
      update(v * 2 + 1, tm + 1, tr, pos, val);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
int sum(int v, int tl, int tr, int l, int r) {
  if (l == tl && r == tr) return t[v];
  if (l > r) return 0;
  int tm = (tl + tr) / 2;
  return sum(v * 2, tl, tm, l, min(r, tm)) +
         sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> q;
  ri = n - 1;
  for (int i = 0; i < n; i++) update(1, 0, n - 1, i, 1);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int p;
      cin >> p;
      int len = ri - le + 1;
      if (2 * p > len) {
        if (dir == -1) {
          for (int i = ri - p; i >= le; i--)
            update(1, 0, n - 1, ri - p + (ri - p - i) + 1,
                   sum(1, 0, n - 1, i, i));
          le += len - p;
          dir = 0;
        } else {
          for (int i = le + p; i <= ri; i++)
            update(1, 0, n - 1, le + p - (i - le - p) - 1,
                   sum(1, 0, n - 1, i, i));
          ri -= len - p;
          dir = -1;
        }
      } else {
        if (!dir) {
          for (int i = p - 1; i >= 0; i--)
            update(1, 0, n - 1, p + (p - i) - 1 + le,
                   sum(1, 0, n - 1, i + le, i + le));
          le += p;
        } else {
          for (int i = ri - p + 1; i <= ri; i++)
            update(1, 0, n - 1, ri - p - (i - ri + p) + 1,
                   sum(1, 0, n - 1, i, i));
          ri -= p;
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      if (!dir)
        cout << sum(1, 0, n - 1, l + le, r + le - 1) << endl;
      else
        cout << sum(1, 0, n - 1, ri - r + 1, ri - l) << endl;
    }
  }
}
