#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
  int tbl[100001];
  Fenwick() { memset(tbl, 0, sizeof tbl); }
  inline void update(int p, int v) {
    while (p < 100001) {
      tbl[p] += v;
      p += p & -p;
    }
  }
  inline int sum(int p) {
    int v = 0;
    while (p) {
      v += tbl[p];
      p -= p & -p;
    }
    return v;
  }
  inline int sum(int l, int r) { return sum(r) - sum(l); }
};
int n, q, t, st, nd;
int flip, p, l, r;
int wid[100001];
Fenwick bit;
int main() {
  cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    wid[i] = 1;
    bit.update(i + 1, 1);
  }
  st = 0;
  nd = n;
  flip = 0;
  for (int i = 0; i < q; ++i) {
    cin >> t;
    if (t == 1) {
      cin >> p;
      int len = nd - st;
      bool do_flip = 2 * p > len;
      if (do_flip) {
        p = len - p;
        flip = !flip;
      }
      if (flip) {
        for (int i = 0; i < p; ++i) {
          bit.update(nd - p - i, wid[nd - p + i]);
          wid[nd - p - i - 1] += wid[nd - p + i];
        }
        nd -= p;
      } else {
        for (int i = 0; i < p; ++i) {
          bit.update(st + p + i + 1, wid[st + p - i - 1]);
          wid[st + p + i] += wid[st + p - i - 1];
        }
        st += p;
      }
    } else {
      cin >> l >> r;
      if (flip) {
        cout << bit.sum(nd - r, nd - l) << endl;
      } else {
        cout << bit.sum(st + l, st + r) << endl;
      }
    }
  }
  return 0;
}
