#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int a[maxn], c[maxn], n, q;
int lowbit(int x) { return x & (-x); }
void update(int x, int v) {
  a[x] += v;
  while (x <= n) {
    c[x] += v;
    x += lowbit(x);
  }
}
int sum(int x) {
  int s = 0;
  while (x > 0) {
    s += c[x];
    x -= lowbit(x);
  }
  return s;
}
int main() {
  memset(a, 0, sizeof(a));
  memset(c, 0, sizeof(c));
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) update(i, 1);
  bool flag = false;
  int l = 1, r = n;
  for (int i = 0; i < q; i++) {
    int tmp, ql, qr, y;
    scanf("%d", &tmp);
    if (tmp == 1) {
      scanf("%d", &y);
      bool fg = (y * 2) > (r - l + 1);
      int mid;
      if (flag)
        mid = r - y;
      else
        mid = l + y - 1;
      int ll = mid - l + 1, rr = r - mid;
      if (ll <= rr) {
        for (int i = l; i <= mid; i++) update(2 * mid - i + 1, a[i]);
        l = mid + 1;
      } else {
        for (int i = r; i > mid; i--) update(2 * mid - i + 1, a[i]);
        r = mid;
      }
      flag ^= fg;
    } else {
      scanf("%d%d", &ql, &qr);
      if (!flag)
        printf("%d\n", sum(qr + l - 1) - sum(ql + l - 1));
      else
        printf("%d\n", sum(r - ql) - sum(r - qr));
    }
  }
}
