#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct BIT {
  const int BIAS = 5;
  int n;
  vector<int> v, x;
  BIT(int _n = N) : n(_n), v(_n, 0), x(_n, 0) {}
  int get_v(int p) { return v[p + BIAS]; }
  void modify(int p, int o) {
    p += BIAS;
    v[p] += o;
    for (int i = p; i < n; i += i & -i) x[i] += o;
  }
  int sum(int p) {
    p += BIAS;
    int ret = 0;
    for (int i = p; i > 0; i -= i & -i) ret += x[i];
    return ret;
  }
  void to_s(int left, int right) {
    printf("[%d, %d] => ", left, right);
    for (int i = left; i <= right; ++i) printf("%d ", v[i + BIAS]);
    puts("");
  }
} T;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i) T.modify(i, 1);
  int left = 0, right = n - 1, mid;
  bool inv = false;
  for (int t, p, l, r; q--;) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &p);
      mid = left + p - 1;
      if (inv) mid = right - p;
      if (mid - left + 1 <= right - mid) {
        for (int i = left; i <= mid; ++i) {
          int v = T.get_v(i);
          T.modify(2 * mid + 1 - i, v);
          T.modify(i, -v);
        }
        left = mid + 1;
        if (inv) inv = !inv;
      } else {
        for (int i = mid + 1; i <= right; ++i) {
          int v = T.get_v(i);
          T.modify(2 * mid + 1 - i, v);
          T.modify(i, -v);
        }
        right = mid;
        inv = !inv;
        if (!inv) inv = !inv;
      }
    } else {
      scanf("%d%d", &l, &r);
      int tot = 0;
      if (inv)
        tot = T.sum(right - l) - T.sum(right - r);
      else
        tot = T.sum(r - 1 + left) - T.sum(l - 1 + left);
      printf("%d\n", tot);
    }
  }
  return 0;
}
