#include <bits/stdc++.h>
using namespace std;
int n, t, p, l, r, st, dr, rw, m;
int AIB[100005];
void add(int pos, int val) {
  pos += 2;
  for (int i = pos; i < 100005; i += i & (i - 1) ^ i) AIB[i] += val;
}
int query(int pos) {
  pos += 2;
  int ans = 0;
  for (int i = pos; i >= 1; i -= i & (i - 1) ^ i) ans += AIB[i];
  return ans;
}
int getVal(int pos) { return query(pos) - query(pos - 1); }
int getAns(int l, int r) {
  l++;
  if (!rw) {
    l += st - 1;
    r += st - 1;
    return query(r) - query(l - 1);
  } else {
    l = dr - l + 1;
    r = dr - r + 1;
    return query(l) - query(r - 1);
  }
}
void cut(int p) {
  if (!rw)
    p += st - 1;
  else
    p = dr - p;
  if (p <= (st + dr) / 2) {
    for (int i = st; i <= p; i++) {
      add(p + (p - i + 1), getVal(i));
    }
    st = p + 1;
    if (rw) rw = 0;
  } else {
    for (int i = dr; i > p; i--) {
      add(p - (i - p - 1), getVal(i));
    }
    dr = p;
    if (!rw) rw = 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  st = 1, dr = n;
  for (int i = 1; i <= n; i++) add(i, 1);
  for (int i = 1; i <= m; i++) {
    cin >> t;
    if (t == 1) {
      cin >> p;
      cut(p);
    } else {
      cin >> l >> r;
      cout << getAns(l, r) << '\n';
    }
  }
  return 0;
}
