#include <bits/stdc++.h>
using namespace std;
int t[4 * 200010];
int lazy[4 * 200010];
void refresh(int root, int rl, int rr) {
  if (lazy[root] != 0) {
    t[root] += (rr - rl + 1) * lazy[root];
    if (rl != rr) {
      lazy[2 * root + 1] += lazy[root];
      lazy[2 * root + 2] += lazy[root];
    }
    lazy[root] = 0;
  }
}
void update(int root, int rl, int rr, int a, int b, int val) {
  refresh(root, rl, rr);
  if (a > rr || b < rl) return;
  if (a <= rl && b >= rr) {
    lazy[root] += val;
    refresh(root, rl, rr);
    return;
  }
  int rm = (rl + rr) / 2;
  update(2 * root + 1, rl, rm, a, b, val);
  update(2 * root + 2, rm + 1, rr, a, b, val);
  t[root] = t[2 * root + 1] + t[2 * root + 2];
}
int query(int root, int rl, int rr, int a, int b) {
  refresh(root, rl, rr);
  if (a > rr || b < rl) return 0;
  if (a <= rl && b >= rr) {
    return t[root];
  }
  int rm = (rl + rr) / 2;
  int ans =
      query(2 * root + 1, rl, rm, a, b) + query(2 * root + 2, rm + 1, rr, a, b);
  t[root] = t[2 * root + 1] + t[2 * root + 2];
  return ans;
}
int main() {
  int n, q;
  scanf(" %d %d", &n, &q);
  int esq = 0;
  int dir = n - 1;
  update(0, 0, n - 1, 0, n - 1, 1);
  int inv = 0;
  for (int i = 0; i < (q); ++i) {
    int t, a, b;
    scanf(" %d %d", &t, &a);
    a--;
    int sz = dir - esq + 1;
    if (t == 1) {
      if (inv) a = (sz - a - 1) - 1;
      if (a >= (dir - esq + 1) / 2) {
        for (int x = a + 1, y = a; esq + x <= dir; x++, y--) {
          int vx = query(0, 0, n - 1, esq + x, esq + x);
          update(0, 0, n - 1, esq + y, esq + y, vx);
          update(0, 0, n - 1, esq + x, esq + x, -vx);
        }
        dir = esq + a;
        if (!inv) inv ^= 1;
      } else {
        for (int x = a, y = a + 1; x >= 0; x--, y++) {
          int vx = query(0, 0, n - 1, esq + x, esq + x);
          update(0, 0, n - 1, esq + y, esq + y, vx);
          update(0, 0, n - 1, esq + x, esq + x, -vx);
        }
        if (inv) inv ^= 1;
        esq = esq + a + 1;
      }
    } else {
      a++;
      int b;
      scanf(" %d", &b);
      b--;
      if (inv) a = (sz - a - 1);
      if (inv) b = (sz - b - 1);
      int na = min(a, b);
      int nb = max(a, b);
      printf("%d\n", query(0, 0, n - 1, esq + na, esq + nb));
    }
  }
  return 0;
}
