#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
struct BIT {
  int a[N], n;
  void Init(int n) { this->n = n; }
  void add(int p, int v) {
    for (p = p + 1; p <= n; p += p & -p) a[p] += v;
    return;
  }
  int query(int p) {
    int res = 0;
    for (p = p + 1; p >= 1; p -= p & -p) res += a[p];
    return res;
  }
} * TA;
struct Node {
  int val, idx;
  Node(int v, int i) {
    val = v;
    idx = i;
  }
};
void update(Node &des, Node src) {
  des.val += src.val;
  TA->add(des.idx, src.val);
}
int main() {
  int n, q;
  cin >> n >> q;
  TA = new BIT();
  TA->Init(n);
  deque<Node> Q;
  for (int i = 0; i < n; i++) TA->add(i, 1), Q.push_back(Node(1, i));
  int s = 0;
  for (int i = 0; i < q; i++) {
    int f;
    scanf("%d", &f);
    if (f == 1) {
      int p;
      scanf("%d", &p);
      if (2 * p <= Q.size()) {
        if (s == 0) {
          for (int i = 0; i < p; i++) {
            update(Q[2 * p - 1 - i], Q[i]);
          }
          for (int i = 0; i < p; i++) Q.pop_front();
        } else {
          for (int i = (int)Q.size() - 1; i >= Q.size() - p; i--) {
            update(Q[2 * (Q.size() - p) - 1 - i], Q[i]);
          }
          for (int i = 0; i < p; i++) Q.pop_back();
        }
      } else {
        if (s == 0) {
          for (int i = (int)Q.size() - 1; i >= p; i--) {
            update(Q[2 * p - 1 - i], Q[i]);
          }
          int d = (int)Q.size() - p;
          for (int i = 0; i < d; i++) Q.pop_back();
        } else {
          for (int i = 0; i < Q.size() - p; i++) {
            update(Q[2 * (Q.size() - p) - 1 - i], Q[i]);
          }
          int d = (int)Q.size() - p;
          for (int i = 0; i < d; i++) Q.pop_front();
        }
        s = s ^ 1;
      }
    } else {
      int L, R;
      scanf("%d %d", &L, &R);
      --R;
      if (s == 1) {
        int ll = L, rr = R;
        L = Q[Q.size() - rr - 1].idx;
        R = Q[Q.size() - ll - 1].idx;
      } else {
        L = Q[L].idx, R = Q[R].idx;
      }
      printf("%d\n", TA->query(R) - TA->query(L - 1));
    }
  }
}
