#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <typename T>
void DBG(const char* name, T&& H) {
  cerr << name << " = " << H << ')' << '\n';
}
template <typename T, typename... Args>
void DBG(const char* names, T&& H, Args&&... args) {
  const char* NEXT = strchr(names + 1, ',');
  cerr.write(names, NEXT - names) << " = " << H << " |";
  DBG(NEXT + 1, args...);
}
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ld PI = acos(-1.0);
const ll maxN = 2001;
struct BIT {
  using T = long long;
  vector<T> arr;
  T total;
  BIT(T s = 1e6) {
    total = 0;
    arr.assign(s + 1, 0);
  }
  T sum(T pos) {
    T ans = 0;
    while (pos > 0) {
      ans += arr[pos];
      pos = pos - (pos & (-pos));
    }
    return ans;
  }
  void update(T pos, T val) {
    while ((pos > 0) && (pos < arr.size())) {
      arr[pos] += val;
      pos = pos + (pos & (-pos));
    }
  }
  T rQuery(T l, T r) { return sum(r) - sum(l - 1); }
};
int L, R;
bool isFlip = false;
inline int iC(int idx) {
  if (!isFlip)
    return L + idx - 1;
  else
    return R - idx + 1;
}
inline int add(int idx, int val) {
  if (!isFlip)
    return idx + val;
  else
    return idx - val;
}
void Solve() {
  int n, q;
  cin >> n >> q;
  L = 1, R = n;
  BIT fold(2 * n);
  for (int i = 1; i <= n; i++) fold.update(i, 1);
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int p;
      cin >> p;
      if (p <= (R - L + 1) / 2) {
        int idx = iC(p + 1);
        for (int i = iC(p); (i >= L) && (i <= R); i = add(i, -1)) {
          fold.update(idx, fold.rQuery(i, i));
          idx = add(idx, 1);
        }
        if (!isFlip)
          L += p;
        else
          R -= p;
      } else {
        int idx = iC(p);
        for (int i = iC(p + 1); (i >= L) && (i <= R); i = add(i, 1)) {
          fold.update(idx, fold.rQuery(i, i));
          idx = add(idx, -1);
        }
        if (isFlip) {
          L += (R - L + 1) - p;
          isFlip = 0;
        } else {
          R = p + L - 1;
          isFlip = 1;
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      l++;
      l = iC(l);
      r = iC(r);
      if (l > r) swap(l, r);
      cout << fold.rQuery(l, r) << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    Solve();
  }
  return 0;
}
