#include <bits/stdc++.h>
using namespace std;
struct node {
  shared_ptr<node> L, R;
  long long val;
  long long lazy;
  node(long long val, long long lazy) : val(val), lazy(lazy) {}
};
struct segTree {
  long long def;
  long long (*op)(long long, long long);
  void (*lazyFunc2)(shared_ptr<node> const&, long long, long long, long long,
                    long long (*op)(long long, long long));
  long long maxN;
  shared_ptr<node> root;
  segTree(long long (*op)(long long, long long),
          void (*lazyFunc2)(shared_ptr<node> const&, long long, long long,
                            long long, long long (*op)(long long, long long)),
          long long defaultVal, long long maxVal = 1e15)
      : def(defaultVal), op(op), lazyFunc2(lazyFunc2), maxN(maxVal) {
    root = make_shared<node>(defaultVal, defaultVal);
  }
  void lazyFunc(const shared_ptr<node>& u, long long currLo, long long currHi) {
    if (!(u->L)) {
      u->L = make_shared<node>(def, def);
    }
    if (!(u->R)) {
      u->R = make_shared<node>(def, def);
    }
    if (u->lazy == def) return;
    lazyFunc2(u, currLo, currHi, def, op);
  }
  void upd(long long lo, long long hi, long long num) {
    _upd(lo, hi, num, root, 0, maxN);
  }
  void _upd(long long lo, long long hi, long long num,
            const shared_ptr<node>& u, long long currLo, long long currHi) {
    lazyFunc(u, currLo, currHi);
    if (currLo > hi || currHi < lo) return;
    if (currLo >= lo && currHi <= hi) {
      u->lazy = op(u->lazy, num);
      lazyFunc(u, currLo, currHi);
      return;
    }
    long long mid = (currLo + currHi) / 2;
    _upd(lo, hi, num, u->L, currLo, mid);
    _upd(lo, hi, num, u->R, mid + 1, currHi);
    u->val = op(u->L->val, u->R->val);
  }
  long long query(long long lo, long long hi) {
    return _query(lo, hi, root, 0, maxN);
  }
  long long _query(long long lo, long long hi, const shared_ptr<node>& u,
                   long long currLo, long long currHi) {
    if (currLo > hi || currHi < lo) return def;
    lazyFunc(u, currLo, currHi);
    if (currLo >= lo && currHi <= hi) {
      return u->val;
    }
    long long mid = (currLo + currHi) / 2;
    long long l1 = def, l2 = def;
    if (u->L) l1 = _query(lo, hi, u->L, currLo, mid);
    if (u->R) l2 = _query(lo, hi, u->R, mid + 1, currHi);
    return op(l1, l2);
  }
};
long long sum1(long long i, long long j) { return i + j; }
void sum_lazy(const shared_ptr<node>& u, long long currLo, long long currHi,
              long long def, long long (*op)(long long, long long)) {
  u->L->lazy = op(u->L->lazy, u->lazy);
  u->R->lazy = op(u->R->lazy, u->lazy);
  u->val += (currHi - currLo + 1) * (u->lazy);
  u->lazy = def;
}
int main() {
  int n, q;
  cin >> n >> q;
  int lo = 0, hi = n - 1;
  bool flip = 0;
  segTree s(sum1, sum_lazy, 0, 1e5 + 5);
  s.upd(0, n - 1, 1);
  for (int x = 0; x < q; x++) {
    int t;
    cin >> t;
    if (t == 1) {
      int p;
      cin >> p;
      if (flip) p = hi - lo + 1 - p;
      if (p <= (hi - lo + 1) / 2) {
        for (int x = 1; p - x >= 0; x++) {
          s.upd(lo + p + x - 1, lo + p + x - 1,
                s.query(lo + p - x, lo + p - x));
          s.upd(lo + p - x, lo + p - x, 0);
        }
        lo += p;
        flip = 0;
      } else {
        for (int x = 1; p + lo + x - 1 <= hi; x++) {
          s.upd(p + lo - x, p + lo - x,
                s.query(p + lo + x - 1, p + lo + x - 1));
          s.upd(p + lo + x - 1, p + lo + x - 1, 0);
        }
        hi = lo + p - 1;
        flip = 1;
      }
    } else {
      int a, b;
      cin >> a >> b;
      b--;
      if (flip) {
        int tmpA = a;
        a = hi - b;
        b = hi - tmpA;
      } else {
        a += lo;
        b += lo;
      }
      cout << s.query(a, b) << endl;
    }
  }
}
