#include <bits/stdc++.h>
using namespace std;
template <typename SegNode>
struct LazySegTree {
  vector<SegNode> tree, lazy, arr;
  int n;
  LazySegTree(int n) : n(n) {
    tree.assign(4 * n, SegNode(0));
    lazy.assign(4 * n, SegNode(0));
  }
  LazySegTree(int n, vector<SegNode> arr) : n(n) {
    tree.assign(4 * n, SegNode(0));
    lazy.assign(4 * n, SegNode(0));
    arr = arr;
    build(0, n - 1, 0);
  }
  SegNode merge(SegNode l, SegNode r) { return l + r; }
  void build(int ss, int se, int si) {
    if (ss == se) {
      tree[si] = arr[ss];
    } else {
      int mid = ss + se >> 1;
      build(ss, mid, 2 * si + 1);
      build(mid + 1, se, 2 * si + 2);
      tree[si] = merge(tree[2 * si + 1], tree[2 * si + 2]);
    }
  }
  SegNode query(int qs, int qe) { return query(qs, qe, 0, n - 1, 0); }
  SegNode query(int qs, int qe, int ss, int se, int si) {
    pushdown(si, ss, se);
    if (ss >= qs && se <= qe) {
      return tree[si];
    }
    int mid = ss + se >> 1;
    if (qe <= mid) {
      return query(qs, qe, ss, mid, 2 * si + 1);
    } else if (qs >= mid + 1) {
      return query(qs, qe, mid + 1, se, 2 * si + 2);
    } else {
      return merge(query(qs, qe, ss, mid, 2 * si + 1),
                   query(qs, qe, mid + 1, se, 2 * si + 2));
    }
  }
  void update(int qs, int qe, int val) { update(qs, qe, val, 0, n - 1, 0); }
  void update(int qs, int qe, int val, int ss, int se, int si) {
    pushdown(si, ss, se);
    if (qs > se || qe < ss) return;
    if (ss >= qs && se <= qe) {
      lazy[si] = val;
      pushdown(si, ss, se);
    } else {
      int mid = ss + se >> 1;
      update(qs, qe, val, ss, mid, 2 * si + 1);
      update(qs, qe, val, mid + 1, se, 2 * si + 2);
      tree[si] = merge(tree[2 * si + 1], tree[2 * si + 2]);
    }
  }
  void pushdown(int si, int ss, int se) {
    if (lazy[si]) {
      tree[si] += lazy[si];
      if (ss != se) {
        lazy[2 * si + 1] += lazy[si];
        lazy[2 * si + 2] += lazy[si];
      }
      lazy[si] = 0;
    }
  }
};
void solve() {
  int n, q;
  cin >> n >> q;
  LazySegTree<int> tree(n);
  for (int i = 0; i < n; i++) tree.update(i, i, 1);
  int st = 0, en = n, swp = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int p;
      cin >> p;
      if (p <= en - st - p) {
        if (!swp) {
          for (int i = p, j = p - 1; j >= 0; i++, j--) {
            tree.update(i + st, i + st, tree.query(j + st, j + st));
          }
          st += p;
        } else {
          for (int i = p + 1, j = p; j > 0; i++, j--) {
            tree.update(en - i, en - i, tree.query(en - j, en - j));
          }
          en -= p;
        }
      } else {
        if (!swp) {
          for (int i = p - 1, j = p; j < en - st; i--, j++) {
            tree.update(i + st, i + st, tree.query(j + st, j + st));
          }
          en = st + p;
        } else {
          for (int i = p, j = p + 1; j < en - st + 1; i--, j++) {
            tree.update(en - i, en - i, tree.query(en - j, en - j));
          }
          st += en - st - p;
        }
        swp ^= 1;
      }
    } else {
      int l, r;
      cin >> l >> r;
      if (!swp) {
        cout << tree.query(l + st, r - 1 + st) << "\n";
      } else {
        cout << tree.query(en - r, en - (l + 1)) << "\n";
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cout << fixed << setprecision(20);
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
