#include <bits/stdc++.h>
using namespace std;
struct BIT {
  int n;
  int bit[100010];
  void init(int _n) {
    n = _n;
    for (int i = 1; i <= n; i++) {
      bit[i] = 0;
    }
  }
  void add(int p, int v) {
    for (; p <= n; p += p & -p) bit[p] += v;
  }
  int sum(int p) {
    int res = 0;
    for (; p > 0; p -= p & -p) res += bit[p];
    return res;
  }
} c;
int a[100010];
int main(void) {
  int n, q;
  cin >> n >> q;
  c.init(n);
  for (int i = 1; i <= n; i++) {
    c.add(i, a[i] = 1);
  }
  int pl = 1, pr = n, rev = 0;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      int p;
      cin >> p;
      if (p > (pr - pl + 1) / 2) {
        p = (pr - pl + 1) - p;
        rev ^= 1;
      }
      if (!rev) {
        for (int i = pl + p - 1, j = pl + p; i >= pl; i--, j++) {
          c.add(i, -a[i]);
          c.add(j, a[i]);
          a[j] += a[i], a[i] = 0;
        }
        pl = pl + p;
      } else {
        for (int i = pr - p, j = pr - p + 1; j <= pr; i--, j++) {
          c.add(i, a[j]);
          c.add(j, -a[j]);
          a[i] += a[j], a[j] = 0;
        }
        pr = pr - p;
      }
    } else {
      int l, r;
      cin >> l >> r;
      if (!rev)
        l = pl + l, r = pl + r - 1;
      else
        l = pr - l, r = pr - r + 1, swap(l, r);
      cout << c.sum(r) - c.sum(l - 1) << endl;
    }
  }
  return 0;
}
