#include <bits/stdc++.h>
using namespace std;
int A[100005];
int segTree[300005];
void maketree(int l, int r, int ind) {
  if (l == r) {
    segTree[ind] = A[l];
    return;
  }
  int mid = l + (r - l) / 2;
  maketree(l, mid, ind * 2);
  maketree(mid + 1, r, ind * 2 + 1);
  segTree[ind] = segTree[ind * 2] + segTree[ind * 2 + 1];
}
void update(int l, int r, int curind, int tofind, int newval) {
  if (tofind > r || tofind < l) return;
  if (l == r) {
    A[l] = newval;
    segTree[curind] = newval;
    return;
  }
  int mid = l + (r - l) / 2;
  update(l, mid, curind * 2, tofind, newval);
  update(mid + 1, r, curind * 2 + 1, tofind, newval);
  segTree[curind] = segTree[curind * 2] + segTree[curind * 2 + 1];
}
int sum(int l, int r, int curind, int lr, int rr) {
  int mid = l + (r - l) / 2;
  if (l == r) return segTree[curind];
  if (l >= lr && r <= rr) return segTree[curind];
  if ((mid + 1) > rr)
    return sum(l, mid, curind * 2, lr, rr);
  else if (mid < lr)
    return sum(mid + 1, r, curind * 2 + 1, lr, rr);
  else
    return sum(l, mid, curind * 2, lr, rr) +
           sum(mid + 1, r, curind * 2 + 1, lr, rr);
}
int main() {
  int N, Q;
  scanf("%d%d", &N, &Q);
  for (int i = 1; i <= N; i++) A[i] = 1;
  maketree(1, N, 1);
  int curstart = 1, curend = N;
  bool flip = false;
  while (Q--) {
    int choice;
    scanf("%d", &choice);
    if (choice == 1) {
      int crease;
      scanf("%d", &crease);
      if (flip) {
        if (crease > (curend - curstart + 1) / 2) {
          crease = (curend - curstart + 1) - crease;
          for (int j = 1, i = curstart + crease; i < curstart + (2 * crease);
               i++, j += 2)
            update(1, N, 1, i, A[i] + A[i - j]);
          for (int i = curstart; i < curstart + crease; i++)
            update(1, N, 1, i, 0);
          curstart += crease;
          flip = false;
        } else {
          for (int j = 1, i = curend - crease; i > curend - (2 * crease);
               i--, j += 2)
            update(1, N, 1, i, A[i] + A[i + j]);
          for (int i = curend; i > curend - crease; i--) update(1, N, 1, i, 0);
          curend -= crease;
        }
      } else {
        if (crease > (curend - curstart + 1) / 2) {
          crease = (curend - curstart + 1) - crease;
          for (int j = 1, i = curend - crease; i > curend - (2 * crease);
               i--, j += 2)
            update(1, N, 1, i, A[i] + A[i + j]);
          for (int i = curend; i > curend - crease; i--) update(1, N, 1, i, 0);
          curend -= crease;
          flip = !flip;
        } else {
          for (int j = 1, i = curstart + crease; i < curstart + (2 * crease);
               i++, j += 2)
            update(1, N, 1, i, A[i] + A[i - j]);
          for (int i = curstart; i < curstart + crease; i++)
            update(1, N, 1, i, 0);
          curstart += crease;
        }
      }
    }
    if (choice == 2) {
      int l, r;
      scanf("%d%d", &l, &r);
      if (flip)
        printf("%d\n",
               sum(1, N, 1, (curend + 1) - (r), (curend + 1) - (l + 1)));
      else
        printf("%d\n", sum(1, N, 1, l + curstart, r + curstart - 1));
    }
  }
  return 0;
}
