#include <bits/stdc++.h>
using namespace std;
int n, m;
int t[100010], now[100010];
int be, en, i, j, a, b, w;
bool turn;
inline int lowbit(int x) { return (x & -x); }
void add(int x, int value) {
  for (int i = x; i <= en; i += lowbit(i)) t[i] += value;
}
int get(int x) {
  int sum = 0;
  for (int i = x; i; i -= lowbit(i)) sum += t[i];
  return sum;
}
int main() {
  scanf("%d%d", &n, &m);
  be = 1, en = n;
  for (i = 1; i <= n; i++) {
    now[i] = 1;
    add(i, 1);
  }
  turn = 0;
  for (i = 0; i < m; i++) {
    scanf("%d", &a);
    if (a == 2) {
      scanf("%d%d", &a, &b);
      if (!turn)
        printf("%d\n", get(be + b - 1) - get(be + a - 1));
      else
        printf("%d\n", get(en - a) - get(en - b));
    } else if (a == 1) {
      scanf("%d", &a);
      w = en - be + 1;
      if (turn) a = w - a;
      if (a <= w / 2) {
        for (j = 1; j <= a; j++)
          now[be + a + j - 1] += now[be + a - j],
              add(be + a + j - 1, now[be + a - j]);
        be = be + a;
        if (turn) turn = 0;
      } else {
        for (j = 1; j <= w - a; j++)
          now[be + a - j] += now[be + a + j - 1],
              add(be + a - j, now[be + a + j - 1]);
        en = be + a - 1;
        turn = 1;
      }
    }
  }
  return 0;
}
