#include <bits/stdc++.h>
using namespace std;
int n, q, flip = 0, tr[100005], s, t, A[100005];
int lowbit(int x) { return x & (-x); }
void modify(int x, int d) {
  while (x <= n) tr[x] += d, x += lowbit(x);
  return;
}
int query(int x) {
  int s = 0;
  while (x) s += tr[x], x -= lowbit(x);
  return s;
}
int main() {
  int i, j, num, l, r;
  scanf("%d %d", &n, &q), n++;
  for (i = 1; i < n; i++) modify(i, 1), A[i] = 1;
  s = 1, t = n;
  for (i = 1; i <= q; i++) {
    scanf("%d", &num);
    if (num == 1) {
      scanf("%d", &l), l++;
      if (flip)
        l = t - l + 1;
      else
        l = s + l - 1;
      if (!flip) {
        if (l - s <= (t - s) / 2) {
          for (j = s; j < l; j++) {
            modify(j, -A[j]);
            A[2 * l - j - 1] += A[j];
            modify(2 * l - j - 1, A[j]);
            A[j] = 0;
          }
          s += l - s;
        } else {
          flip ^= 1;
          for (j = t - 1; j >= l; j--) {
            modify(j, -A[j]);
            A[2 * l - j - 1] += A[j];
            modify(2 * l - j - 1, A[j]);
            A[j] = 0;
          }
          t -= t - l;
        }
      } else {
        if (l - s <= (t - s) / 2) {
          flip ^= 1;
          for (j = s; j < l; j++) {
            modify(j, -A[j]);
            A[2 * l - j - 1] += A[j];
            modify(2 * l - j - 1, A[j]);
            A[j] = 0;
          }
          s += l - s;
        } else {
          for (j = t - 1; j >= l; j--) {
            modify(j, -A[j]);
            A[2 * l - j - 1] += A[j];
            modify(2 * l - j - 1, A[j]);
            A[j] = 0;
          }
          t -= t - l;
        }
      }
    }
    if (num == 2) {
      scanf("%d %d", &l, &r), l++, r++;
      if (!flip) {
        l = l + s - 1, r = r + s - 1;
        printf("%d\n", query(r - 1) - query(l - 1));
      } else {
        l = t - l + 1, r = t - r + 1;
        printf("%d\n", query(l - 1) - query(r - 1));
      }
    }
  }
  return 0;
}
