#include <bits/stdc++.h>
using namespace std;
bool dir;
int ini, n, tree[200005], sz;
void update(int pos, int delta) {
  for (; pos <= 200005; pos += pos & -pos) tree[pos] += delta;
}
int read(int pos) {
  int answer = 0;
  for (; pos > 0; pos -= pos & -pos) answer += tree[pos];
  return answer;
}
int read(int le, int ri) { return read(ri) - read(le - 1); }
int main() {
  int q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; ++i) update(i, 1);
  sz = n;
  dir = 1;
  ini = 1;
  int tipo, x, y;
  while (q--) {
    scanf("%d %d", &tipo, &x);
    if (tipo == 1) {
      if (dir == 0) x = sz - x;
      if (x + x <= sz) {
        for (int pos = ini + x, back = pos - 1; pos < ini + x + x;
             pos++, back--) {
          int p = read(back, back);
          update(back, -p);
          update(pos, +p);
        }
        ini = ini + x;
        sz -= x;
        if (dir == 0) dir = 1;
      } else {
        for (int pos = ini + x, back = pos - 1; pos < ini + sz; pos++, back--) {
          int p = read(pos, pos);
          update(pos, -p);
          update(back, +p);
        }
        sz = x;
        if (dir == 1) dir = 0;
      }
    } else {
      scanf("%d", &y);
      ++x;
      if (dir == 0) {
        x = sz - x + 1;
        y = sz - y + 1;
        swap(x, y);
      }
      int answer = read(x + ini - 1, y + ini - 1);
      printf("%d\n", answer);
    }
  }
  return 0;
}
