#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int a[MAXN], seg[MAXN * 4];
void upd(int p, int v, int s, int e) {
  if (e - s <= 1) {
    seg[v] = a[s];
    return;
  }
  int m = (s + e) / 2;
  if (p < m)
    upd(p, v * 2, s, m);
  else
    upd(p, v * 2 + 1, m, e);
  seg[v] = seg[v * 2] + seg[v * 2 + 1];
}
int get(int l, int r, int v, int s, int e) {
  if (r <= s || e <= l) return 0;
  if (l <= s && e <= r) return seg[v];
  int m = (s + e) / 2;
  return get(l, r, v * 2, s, m) + get(l, r, v * 2 + 1, m, e);
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; i++) {
    a[i] = 1;
    upd(i, 1, 0, n);
  }
  int m = n;
  int y = 0;
  int rv = 0;
  while (q--) {
    int ty;
    scanf("%d", &ty);
    if (ty == 1) {
      int p;
      scanf("%d", &p);
      if (rv) p = (n - y) - p;
      if (p < (n - y) - p) {
        p += y;
        for (int i = y; i < p; i++) {
          int j = 2 * p - i - 1;
          a[j] += a[i];
          upd(j, 1, 0, m);
        }
        y = p;
        if (rv) rv = 1 - rv;
      } else {
        p += y;
        for (int i = p; i < n; i++) {
          int j = 2 * p - i - 1;
          a[j] += a[i];
          upd(j, 1, 0, m);
        }
        n = p;
        if (!rv) rv = 1 - rv;
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      if (rv == 1) {
        l = (n - y) - l;
        r = (n - y) - r;
        swap(l, r);
      }
      printf("%d\n", get(l + y, r + y, 1, 0, m));
    }
  }
}
