#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
int i, j, l, r, q1, q2, n, m, q, t, a[100500], d[400500], bg = 1, len;
bool rightt = 1;
void built(int i, int p1, int p2) {
  if (p1 == p2) {
    d[i] = a[p1] = 1;
    return;
  }
  int p = (p1 + p2) >> 1;
  built(i << 1, p1, p);
  built((i << 1) + 1, p + 1, p2);
  d[i] = d[i << 1] + d[(i << 1) + 1];
}
void inc(int i, int p1, int p2, int x, int delta) {
  if (p1 == p2) {
    d[i] += delta;
    a[x] += delta;
    return;
  }
  int p = (p1 + p2) >> 1;
  if (x <= p) {
    inc(i << 1, p1, p, x, delta);
  } else {
    inc((i << 1) + 1, p + 1, p2, x, delta);
  }
  d[i] += delta;
}
int sum(int i, int p1, int p2, int q1, int q2) {
  if (p1 == p2) {
    return d[i];
  }
  int p = (p1 + p2) >> 1;
  int res = 0;
  if (p1 >= q1 && p2 <= q2) {
    return d[i];
  }
  if (q1 <= p) {
    res += sum((i << 1), p1, p, q1, q2);
  }
  if (q2 >= p + 1) {
    res += sum((i << 1) + 1, p + 1, p2, q1, q2);
  }
  return res;
}
void solve() {
  scanf("%d%d", &n, &m);
  len = n;
  built(1, 1, n);
  for (j = 1; j <= m; j++) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &q);
      if (q <= len - q) {
        if (rightt) {
          for (i = 1; i <= q; i++) {
            inc(1, 1, n, bg + q - 1 + i, a[bg + q - i]);
          }
          bg += q;
          len -= q;
        } else {
          for (i = 1; i <= q; i++) {
            inc(1, 1, n, bg - q + 1 - i, a[bg - q + i]);
          }
          bg -= q;
          len -= q;
        }
      } else {
        if (!rightt) {
          for (i = 1; i <= len - q; i++) {
            inc(1, 1, n, bg - q + i, a[bg - q + 1 - i]);
          }
          bg -= q - 1;
          len = q;
          rightt = 1;
        } else {
          for (i = 1; i <= len - q; i++) {
            inc(1, 1, n, bg + q - i, a[bg + q - 1 + i]);
          }
          bg += q - 1;
          len = q;
          rightt = 0;
        }
      }
    } else {
      scanf("%d%d", &l, &r);
      if (rightt) {
        printf("%d\n", sum(1, 1, n, bg + l, min(bg + len - 1, bg + r - 1)));
      } else {
        printf("%d\n", sum(1, 1, n, max(bg - len + 1, bg - r + 1), bg - l));
      }
    }
  }
}
int main() {
  srand(1337);
  solve();
  return 0;
}
