#include <bits/stdc++.h>
using namespace std;
int n, Q;
int a[100010];
int c[100010];
inline int lowbit(int x) { return x & (-x); }
inline int update(int x, int num) {
  while (x <= n) {
    c[x] += num;
    x += lowbit(x);
  }
}
inline int sum(int end) {
  int re = 0;
  while (end) {
    re += c[end];
    end -= lowbit(end);
  }
  return re;
}
int main() {
  while (cin >> n >> Q) {
    int curlen = n;
    int curs = 1;
    for (int i = 1; i <= n; i++) {
      a[i] = 1;
      c[i] = lowbit(i);
    }
    bool b = true;
    for (int q = 0; q < Q; q++) {
      int type;
      scanf("%d", &type);
      if (type == 1) {
        int p;
        scanf("%d", &p);
        bool b2 = (p <= curlen / 2);
        if (!(b ^ b2)) {
          if (!b2) p = curlen - p;
          for (int i = 0; i < p; i++) {
            update(curs + p + i, a[curs + p - i - 1]);
            update(curs + p - i - 1, -a[curs + p - i - 1]);
            a[curs + p + i] += a[curs + p - i - 1];
            a[curs + p - i - 1] = 0;
          }
          if (!b2) b = !b;
          curs += p;
          curlen = max(p, curlen - p);
        } else {
          if (!b2) p = curlen - p;
          for (int i = 0; i < p; i++) {
            update(curs + curlen - 1 - (p + i),
                   a[curs + curlen - 1 - (p - i - 1)]);
            update(curs + curlen - 1 - (p - i - 1),
                   -a[curs + curlen - 1 - (p - i - 1)]);
            a[curs + curlen - 1 - (p + i)] +=
                a[curs + curlen - 1 - (p - i - 1)];
            a[curs + curlen - 1 - (p - i - 1)] = 0;
          }
          if (!b2) b = !b;
          curlen = max(p, curlen - p);
        }
      } else {
        int l, r;
        scanf("%d%d", &l, &r);
        int ans = 0;
        if (b) {
          ans = sum(curs + r - 1) - sum(curs + l - 1);
        } else {
          ans = sum(curs + curlen - 1 - l) - sum(curs + curlen - r - 1);
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
