#include <bits/stdc++.h>
using namespace std;
const int INF = (1LL << 31) - 1;
const long long int LINF = (1LL << 62) - 1;
const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;
int N, Q;
long long int V[NMAX];
long long int AIB[NMAX];
void update(int poz, int val) {
  for (; poz <= N; poz += poz & (-poz)) AIB[poz] += val;
}
long long int query(int poz) {
  long long int ans = 0;
  for (; poz; poz -= poz & (-poz)) ans += AIB[poz];
  return ans;
}
int main() {
  int i, j, op, p;
  int left, right, flipped;
  scanf("%d%d", &N, &Q);
  for (i = 1; i <= N; i++) {
    update(i, 1);
    V[i] = 1;
  }
  left = 1;
  right = N;
  while (Q--) {
    scanf("%d", &op);
    op--;
    if (!op) {
      scanf("%d", &p);
      if (!flipped) {
        if ((right - left + 1) - p >= p) {
          for (i = left + p, j = left + p - 1; j >= left; i++, j--) {
            update(i, V[j]);
            V[i] += V[j];
          }
          left += p;
        } else {
          p = (right - left + 1) - p;
          for (i = right - p, j = right - p + 1; j <= right; i--, j++) {
            update(i, V[j]);
            V[i] += V[j];
          }
          right -= p;
          flipped ^= 1;
        }
      } else {
        if ((right - left + 1) - p >= p) {
          for (i = right - p, j = right - p + 1; j <= right; i--, j++) {
            V[i] += V[j];
            update(i, V[j]);
          }
          right -= p;
        } else {
          p = (right - left + 1) - p;
          for (i = left + p, j = left + p - 1; j >= left; i++, j--) {
            V[i] += V[j];
            update(i, V[j]);
          }
          left += p;
          flipped ^= 1;
        }
      }
    } else {
      scanf("%d%d", &i, &j);
      i++;
      if (!flipped)
        printf("%I64d\n", query(left + j - 1) - query(left + i - 2));
      else
        printf("%I64d\n", query(right - i + 1) - query(right - j));
    }
  }
  return 0;
}
