#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e5 + 17;
int n, iman[maxn], q, le, ri;
bool rev;
int hamid(int p) {
  int ans = 0;
  for (p++; p; p ^= p & -p) ans += iman[p];
  return ans;
}
void majid(int p, int v) {
  for (p++; p < maxn; p += p & -p) iman[p] += v;
}
int r_hamid(int l, int r = -1) {
  if (r == -1) r = l + 1;
  return hamid(r - 1) - hamid(l - 1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  ri = n;
  for (int i = 0; i < n; i++) majid(i, 1);
  for (int t, l, r, p; q--;) {
    cin >> t;
    if (t == 1) {
      cin >> p;
      if (rev) p = (ri - le) - p;
      if (rev && 2 * p < ri - le || !rev && 2 * p > ri - le) rev ^= 1;
      p += le;
      if (!rev) {
        for (int i = p; i < p * 2 - le; i++) majid(i, r_hamid(p - (i - p + 1)));
        le = p;
      } else {
        for (int i = p - 1; i >= p * 2 - ri; i--)
          majid(i, r_hamid(p + (p - 1 - i)));
        ri = p;
      }
    } else {
      cin >> l >> r;
      l += le, r += le;
      cout << (rev ? r_hamid(le + (ri - r), le + (ri - l)) : r_hamid(l, r))
           << '\n';
    }
  }
  return 0;
}
