#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, q;
int l, r;
int ts, tree[400000];
void insert(int p, int v) {
  for (p += ts; p; p >>= 1) tree[p] += v;
}
int sum(int l, int r) {
  int res = 0;
  for (l += ts, r += ts; l <= r; l >>= 1, r >>= 1) {
    if (l & 1) res += tree[l++];
    if (!(r & 1)) res += tree[r--];
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &q);
  l = 0, r = n - 1;
  for (ts = 1; ts < n; ts <<= 1)
    ;
  for (int i = 0; i < n; i++) insert(i, 1);
  bool rev = false;
  while (q--) {
    int c, x, y;
    scanf("%d", &c);
    if (c == 1) {
      scanf("%d", &x);
      if (rev)
        x = r - x + 1;
      else
        x = l + x;
      if (x - l < r - x + 1) {
        if (rev) rev = false;
        for (int i = l; i < x; i++) {
          insert(x + (x - l) - (i - l + 1), tree[ts + i]);
          insert(i, -tree[ts + i]);
        }
        l = x;
      } else {
        if (!rev) rev = true;
        x--;
        for (int i = r; i > x; i--) {
          insert(x - (r - x) + (r - i + 1), tree[ts + i]);
          insert(i, -tree[ts + i]);
        }
        r = x;
      }
    } else {
      scanf("%d%d", &x, &y);
      if (rev) {
        swap(x, y);
        x = r - x + 1, y = r - y;
      } else
        x = l + x, y = l + y - 1;
      if (x > y) swap(x, y);
      printf("%d\n", sum(x, y));
    }
  }
  return 0;
}
