#include <bits/stdc++.h>
using namespace std;
const long MAXN = 200010;
long n, q;
long a[MAXN], b[MAXN];
long ml, mr, dir, nowdir;
long get(long x) {
  long tmp = 0;
  while (x > 0) {
    tmp += a[x];
    x -= (x & -x);
  }
  return tmp;
}
long get(long l, long r) { return get(r) - get(l - 1); }
void update(long x, long v) {
  while (x < MAXN) {
    a[x] += v;
    x += (x & -x);
  }
}
void query1(long idx) {
  long len = mr - ml + 1;
  if (idx > len - idx) {
    idx = len - idx;
    nowdir = -nowdir;
  }
  if (nowdir == 1) {
    for (int i = 1; i <= idx; i++) {
      b[ml + idx - 1 + i] += b[ml + idx - 1 - i + 1];
      update(ml + idx - 1 + i, b[ml + idx - 1 - i + 1]);
    }
    ml = ml + idx;
  } else {
    for (int i = 1; i <= idx; i++) {
      b[mr - idx - i + 1] += b[mr - idx + i];
      update(mr - idx - i + 1, b[mr - idx + i]);
    }
    mr = mr - idx;
  }
}
void query2(long l, long r) {
  long cl = r - l;
  if (nowdir == 1) {
    l = ml + l - 1;
    r = l + cl;
  } else {
    r = mr - l + 1;
    l = r - cl;
  }
  cout << get(l, r) << endl;
}
int main() {
  cin >> n >> q;
  ml = 1;
  mr = n;
  for (int i = 1; i <= n; i++) {
    b[i] = 1;
    update(i, 1);
  }
  nowdir = 1;
  for (int i = 1; i <= q; i++) {
    long x, y, l, r;
    cin >> x;
    if (x == 1) {
      cin >> y;
      query1(y);
    } else {
      cin >> l >> r;
      l += 1;
      query2(l, r);
    }
  }
  return 0;
}
