#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, k, x, y;
int t[300030];
bool rev;
int Q(int x) {
  int ret = 0;
  for (; x; x -= (x & (-x))) ret += t[x];
  return ret;
}
void C(int x, int y) {
  for (; x <= n + n + n; x += (x & (-x))) t[x] += y;
}
int main() {
  scanf("%d%d", &n, &m);
  l = n + 1;
  r = n + n;
  for (int i = 1; i <= n; ++i) C(n + i, 1);
  while (m--) {
    scanf("%d", &k);
    if (k == 1) {
      scanf("%d", &x);
      bool flag = (x + x <= (r - l + 1));
      if (rev != flag) {
        if (rev) x = r - l + 1 - x;
        for (int i = l + x - 1, j = l + x; i >= l; --i, ++j) {
          C(j, Q(i) - Q(i - 1));
          r = max(r, j);
        }
        l += x;
      } else {
        if (!rev) x = r - l + 1 - x;
        for (int i = r - x + 1, j = r - x; i <= r; ++i, --j) {
          C(j, Q(i) - Q(i - 1));
          l = min(l, j);
        }
        r -= x;
      }
      if (!flag) rev ^= 1;
    } else {
      scanf("%d%d", &x, &y);
      if (!rev)
        printf("%d\n", Q(l + y - 1) - Q(l + x - 1));
      else
        printf("%d\n", Q(r - x) - Q(r - y));
    }
  }
  return 0;
}
