#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
long long int ft[mx];
void add(int idx, long long int v) {
  for (; idx < mx; idx += (idx & -idx)) ft[idx] += v;
}
long long int qry(int idx) {
  long long int ans = 0;
  for (; idx > 0; idx -= (idx & -idx)) ans += ft[idx];
  return ans;
}
inline long long int range(int l, int r) { return qry(r) - qry(l - 1); }
inline long long int qryat(int idx) { return range(idx, idx); }
int main() {
  ios_base::sync_with_stdio(0);
  int n, q, li, ri, op;
  long long int ans;
  cin >> n >> q;
  memset(ft, 0, sizeof ft);
  for (int i = 1; i <= n; i++) add(i, 1);
  int lft = 1, rht = n;
  while (q--) {
    cin >> op >> li;
    if (op == 1) {
      if (lft <= rht) {
        int ll = lft + li - 1;
        int rr = lft + li;
        int nl = ll - lft + 1;
        int nr = rht - rr + 1;
        while (ll >= lft && rr <= rht) {
          if (nl <= nr) {
            add(rr, qryat(ll));
          } else
            add(ll, qryat(rr));
          ll--, rr++;
        }
        if (nl <= nr)
          lft = lft + li;
        else {
          rht = lft;
          lft = lft + li - 1;
        }
      } else {
        int ll = lft - li + 1;
        int rr = lft - li;
        int nl = lft - ll + 1;
        int nr = rr - rht + 1;
        while (ll <= lft && rr >= rht) {
          if (nl <= nr)
            add(rr, qryat(ll));
          else
            add(ll, qryat(rr));
          ll++, rr--;
        }
        if (nl <= nr)
          lft = lft - li;
        else {
          rht = lft;
          lft = lft - li + 1;
        }
      }
    } else if (op == 2) {
      cin >> ri;
      if (lft <= rht) {
        ans = range(lft + li, lft + ri - 1);
      } else {
        ans = range(lft - ri + 1, lft - li);
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
