#include <bits/stdc++.h>
using namespace std;
struct fenwickTree {
  vector<long long> bit;
  int n;
  fenwickTree() {
    n = (int)1e5 + 3;
    bit.assign(n, 0);
  }
  long long sum(int r) {
    long long ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  void add(int idx, long long d) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += d;
  }
  long long sum(int l, int r) { return sum(r) - sum(l - 1); }
} ft;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  int start = 1, end = n;
  for (int i = 1; i <= n; ++i) {
    ft.add(i, 1);
  }
  int type, p, l, r;
  bool flipped = false;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> p;
      if (2 * p > end - start + 1) {
        flipped = !flipped;
        p = end - start + 1 - p;
      }
      if (!flipped) {
        int pos = start + 2 * p - 1;
        for (int i = 0; i < p; ++i) {
          ft.add(pos, ft.sum(start, start));
          start++;
          pos--;
        }
      } else {
        int pos = end - 2 * p + 1;
        for (int i = 0; i < p; ++i) {
          ft.add(pos, ft.sum(end, end));
          end--;
          pos++;
        }
      }
    } else {
      cin >> l >> r;
      r--;
      if (flipped) {
        cout << ft.sum(end - r, end - l) << '\n';
      } else {
        cout << ft.sum(start + l, start + r) << '\n';
      }
    }
  }
  return 0;
}
