#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int tre[4 * M + 2], a[M + 2];
void build(int pos, int l, int r) {
  if (l == r) {
    tre[pos] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * pos, l, mid);
  build(2 * pos + 1, mid + 1, r);
  tre[pos] = tre[2 * pos] + tre[2 * pos + 1];
}
void update(int pos, int l, int r, int I, int J, int val) {
  if (l > J || r < I) return;
  if (I <= l && J >= r) {
    tre[pos] += val;
    return;
  }
  int mid = (l + r) >> 1;
  update(2 * pos, l, mid, I, J, val);
  update(2 * pos + 1, mid + 1, r, I, J, val);
  tre[pos] = tre[2 * pos] + tre[2 * pos + 1];
}
int qry(int pos, int l, int r, int I, int J) {
  if (l > J || r < I) return 0;
  if (I <= l && J >= r) return tre[pos];
  int mid = (l + r) >> 1;
  return qry(2 * pos, l, mid, I, J) + qry(2 * pos + 1, mid + 1, r, I, J);
}
int main() {
  int n, q, ulta = 0, ses;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) a[i] = 1;
  build(1, 1, n);
  int lft = 1, rgt = n;
  while (q--) {
    int typ, p, l, r;
    scanf("%d", &typ);
    if (typ == 1) {
      int len = rgt - lft + 1;
      scanf("%d", &p);
      if (p > (len / 2)) p = len - p, ulta = 1 - ulta;
      if (ulta == 0) {
        lft += p;
        for (int i = lft - 1, j = 0; j < p; i--, j++) {
          a[lft + j] += a[i];
          update(1, 1, n, lft + j, lft + j, a[i]);
        }
      } else {
        rgt -= p;
        for (int i = rgt + 1, j = 0; j < p; i++, j++) {
          a[rgt - j] += a[i];
          update(1, 1, n, rgt - j, rgt - j, a[i]);
        }
      }
    } else {
      scanf("%d%d", &l, &r);
      if (ulta == 0)
        ses = qry(1, 1, n, lft + l, lft + r - 1);
      else
        ses = qry(1, 1, n, rgt - r + 1, rgt - l);
      printf("%d\n", ses);
    }
  }
}
