#include <bits/stdc++.h>
using namespace std;
struct fenwick {
  vector<int> T;
  int BM;
  fenwick(int n) : T(n, 0), BM(0) {
    while ((1 << (BM + 1)) <= n) ++BM;
  }
  void inc(int x, int add) {
    for (; x < T.size(); x |= x + 1) T[x] += add;
  }
  int query(int a, int b) {
    if (a == 0) {
      int sum = 0;
      for (; b >= 0; b = (b & (b + 1)) - 1) sum += T[b];
      return sum;
    } else
      return query(0, b) - query(0, a - 1);
  }
  int findf(int f, int a, int b) {
    f += (a > 0 ? query(0, a - 1) : 0);
    for (int bitmask = (1 << BM), res = -1, idx = 0;;) {
      if (idx + bitmask - 1 <= b && T[idx + bitmask - 1] <= f) {
        if (T[idx + bitmask - 1] == f && idx + bitmask - 1 >= a)
          res = idx + bitmask - 1;
        else
          idx += bitmask, f -= T[idx - 1];
      }
      if ((bitmask >>= 1) == 0) return res;
    }
  }
};
int cnt[200001];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  fenwick fen(n);
  int s = 0, e = n - 1;
  for (int i = 0; i < n; ++i) {
    fen.inc(i, 1);
    cnt[i] = 1;
  }
  bool flip = false;
  for (int j = 0; j < q; ++j) {
    int c;
    scanf("%d", &c);
    if (c == 1) {
      int x;
      scanf("%d", &x);
      int l = e - s + 1;
      if (x <= l / 2) {
        if (!flip) {
          for (int i = 0; i < x; i++) {
            fen.inc(s + x + i, cnt[s + x - i - 1]);
            cnt[s + x + i] += cnt[s + x - i - 1];
          }
          s += x;
        } else {
          for (int i = 0; i < x; i++) {
            fen.inc(e - x - i, cnt[e - x + 1 + i]);
            cnt[e - x - i] += cnt[e - x + 1 + i];
          }
          e -= x;
        }
      } else {
        if (!flip) {
          for (int i = 0; i < (l - x); i++) {
            fen.inc(s + x - 1 - i, cnt[s + x + i]);
            cnt[s + x - 1 - i] += cnt[s + x + i];
          }
          e -= (l - x);
        } else {
          for (int i = 0; i < (l - x); i++) {
            fen.inc(e - x + 1 + i, cnt[e - x - i]);
            cnt[e - x + 1 + i] += cnt[e - x - i];
          }
          s += (l - x);
        }
        flip = !flip;
      }
    } else {
      int x1, x2;
      scanf("%d%d", &x1, &x2);
      if (!flip)
        printf("%d\n", fen.query(s + x1, s + x2 - 1));
      else
        printf("%d\n", fen.query(e - x2 + 1, e - x1));
    }
  }
  return 0;
}
