#include <bits/stdc++.h>
using namespace std;
int n, q, lp, rp;
bool rev;
long long lo[4 * 100010 + 1], hi[4 * 100010 + 1], tree[4 * 100010 + 1],
    delta[4 * 100010 + 1];
void init(int i, int l, int r) {
  lo[i] = l;
  hi[i] = r;
  if (l == r) return;
  int m = (l + r) / 2;
  init(2 * i, l, m);
  init(2 * i + 1, m + 1, r);
}
void prop(int i) {
  delta[2 * i] += delta[i];
  delta[2 * i + 1] += delta[i];
  delta[i] = 0;
}
void update(int i) {
  tree[i] = tree[2 * i] + delta[2 * i] * (hi[2 * i] - lo[2 * i] + 1) +
            tree[2 * i + 1] +
            delta[2 * i + 1] * (hi[2 * i + 1] - lo[2 * i + 1] + 1);
}
void inc(int i, int l, int r, long long val) {
  if (r < lo[i] || hi[i] < l) return;
  if (hi[i] <= r && lo[i] >= l) {
    delta[i] += val;
    return;
  }
  prop(i);
  inc(2 * i, l, r, val);
  inc(2 * i + 1, l, r, val);
  update(i);
}
void simpleinc(int i, long long val) {
  i += n;
  while (i > 0) {
    tree[i] += val;
    i /= 2;
  }
}
long long query(int i, int l, int r) {
  if (r < lo[i] || hi[i] < l) return 0;
  if (hi[i] <= r && lo[i] >= l) return tree[i] + delta[i] * (hi[i] - lo[i] + 1);
  prop(i);
  long long sumLeft = query(2 * i, l, r);
  long long sumRight = query(2 * i + 1, l, r);
  update(i);
  return sumLeft + sumRight;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  init(1, 0, n);
  rp = n - 1;
  for (int i = 0; i < n; i++) {
    inc(1, i, i, 1);
  }
  while (q--) {
    int t, l, r, x;
    cin >> t;
    if (t == 1) {
      cin >> x;
      if (x * 2 > rp - lp + 1) {
        rev = !rev;
        x = rp - lp + 1 - x;
      }
      if (rev) {
        for (int i = 0; i < x; i++) {
          inc(1, rp - x - i, rp - x - i,
              query(1, rp - x + i + 1, rp - x + i + 1));
        }
        rp -= x;
      } else {
        for (int i = 0; i < x; i++) {
          inc(1, i + lp + x, i + lp + x,
              query(1, lp + x - i - 1, lp + x - i - 1));
        }
        lp += x;
      }
    } else {
      cin >> l >> r;
      int L, R;
      if (rev) {
        L = rp - r + 1;
        R = rp - l;
      } else {
        L = l + lp;
        R = r + lp - 1;
      }
      cout << query(1, L, R) << endl;
    }
  }
}
