#include <bits/stdc++.h>
using namespace std;
const int N = 112345;
int d[N * 4];
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
void update(int l, int r, int id, int ind, int x) {
  if (l == r) {
    d[id] += x;
    return;
  }
  int m = (l + r) >> 1;
  if (ind <= m)
    update(l, m, id + id, ind, x);
  else
    update(m + 1, r, id + id + 1, ind, x);
  d[id] = d[id + id] + d[id + id + 1];
}
int sumlr(int l, int r, int id, int ll, int rr) {
  if (ll <= l && r <= rr) {
    return d[id];
  }
  int m = (l + r) >> 1, s = 0;
  if (ll <= m) s += sumlr(l, m, id + id, ll, rr);
  if (rr > m) s += sumlr(m + 1, r, id + id + 1, ll, rr);
  return s;
}
int main() {
  int n, m, i, j, l, r, x, c, s = 0, t;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    update(1, n, 1, i, 1);
  }
  bool ok = 1;
  int lid = 0;
  int rid = n;
  for (int i = 1; i <= m; i++) {
    t = read();
    if (t == 1) {
      x = read();
      if (ok) {
        if (x <= (rid - lid - x)) {
          int id = lid + x + 1;
          for (int j = lid + x; j > lid; j--) {
            update(1, n, 1, id, sumlr(1, n, 1, j, j));
            id++;
          }
          lid += x;
        } else {
          ok = 0;
          x = (rid - lid - x);
          int id = rid - x;
          for (int j = rid - x + 1; j <= rid; j++) {
            update(1, n, 1, id, sumlr(1, n, 1, j, j));
            id--;
          }
          rid -= x;
        }
      } else {
        if (x <= (rid - lid - x)) {
          int id = rid - x;
          for (int j = rid - x + 1; j <= rid; j++) {
            update(1, n, 1, id, sumlr(1, n, 1, j, j));
            id--;
          }
          rid -= x;
        } else {
          x = (rid - lid - x);
          ok = 1;
          int id = lid + x + 1;
          for (int j = lid + x; j > lid; j--) {
            update(1, n, 1, id, sumlr(1, n, 1, j, j));
            id++;
          }
          lid += x;
        }
      }
    } else {
      l = read();
      r = read();
      if (ok) {
        printf("%d\n", sumlr(1, n, 1, lid + l + 1, lid + r));
      } else {
        printf("%d\n", sumlr(1, n, 1, rid - r + 1, rid - l));
      }
    }
  }
}
