#include <bits/stdc++.h>
using namespace std;
const int N = 100100 << 2;
int tree[N];
int low(int x) { return x & -x; }
int sum(int p) {
  int res = 0;
  for (int i = p; i; i -= low(i)) res += tree[i];
  return res;
}
void add(int p, int v) {
  for (int i = p; i < N; i += low(i)) tree[i] += v;
}
int get(int x) { return sum(x) - sum(x - 1); }
int sum(int l, int r) { return sum(r) - sum(l); }
int n;
int L, R;
int main() {
  int q;
  cin >> n >> q;
  L = 0, R = n;
  for (int i = 1; i <= n; i++) add(i, 1);
  while (q--) {
    int type;
    int p;
    cin >> type;
    if (type == 1) {
      cin >> p;
      int pos;
      if (L < R)
        pos = L + p;
      else
        pos = L - p;
      if (L > R) swap(L, R);
      int w = min(pos - L, R - pos);
      if (w == pos - L) {
        for (int i = 0; i < w; i++) {
          int tmp = get(pos - i);
          add(pos + i + 1, tmp);
        }
        L = pos;
      } else {
        for (int i = 0; i < w; i++) {
          int tmp = get(pos + i + 1);
          add(pos - i, tmp);
        }
        R = L;
        L = pos;
      }
    }
    if (type == 2) {
      int l, r;
      cin >> l >> r;
      int ans;
      if (L < R)
        ans = sum(L + l, L + r);
      else
        ans = sum(L - r, L - l);
      printf("%d\n", ans);
    }
  }
  return 0;
}
