#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
int n, k, typ, p, l, r, t, a[N], f[N];
int st, ed;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    for (int i = 1; i <= n; i++) a[i] = 1, f[i] = f[i - 1] + a[i];
    int pre = 0;
    st = 1;
    ed = n;
    while (k--) {
      scanf("%d", &typ);
      if (typ == 1) {
        scanf("%d", &p);
        if (p <= (ed - st + 1) / 2) {
          for (int i = st + p, t = st + p - 1; i <= ed && t >= st; i++, t--)
            a[i] += a[t];
          st = st + p;
        } else {
          for (int i = st + p - 1, t = st + p; i >= st && t <= ed; i--, t++)
            a[i] += a[t];
          ed = p + st - 1;
          for (int i = st, j = ed; i <= st + (ed - st + 1) / 2; i++, j--)
            swap(a[i], a[j]);
        }
        pre = 1;
      } else {
        if (pre == 1) {
          f[st - 1] = 0;
          for (int i = st; i <= ed; i++) f[i] = f[i - 1] + a[i];
        }
        scanf("%d%d", &l, &r);
        printf("%d\n", f[r + st - 1] - f[l + st - 1]);
        pre = 2;
      }
    }
  }
  return 0;
}
