#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} debug;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
  bool first = true;
  os << "[";
  for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {
    if (!first) os << ", ";
    os << *ii;
    first = false;
  }
  return os << "]";
}
const int NN = 112345;
int seg[NN];
void update(int i, int v) {
  for (i += 5; i < NN; i += i & -i) seg[i] += v;
}
int query(int i) {
  int ans = 0;
  for (i += 5; i > 0; i -= i & -i) ans += seg[i];
  return ans;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) update(i, 1);
  int root = 0, d = -1, width = n;
  while (m--) {
    int t, a, b;
    cin >> t >> a;
    if (t & 1) {
      int L = a, R = width - a;
      if (L < R and d == -1) {
        for (int i = 0; i < L; ++i) {
          int x = root + L - 1 - i, y = root + L + i;
          int v = query(x) - query(x - 1);
          ;
          update(y, v);
        }
        root += L;
      } else if (L < R) {
        for (int i = 0; i < L; ++i) {
          int x = root - L + 1 + i, y = root - L - i;
          int v = query(x) - query(x - 1);
          ;
          update(y, v);
        }
        root -= L;
      } else if (d == -1) {
        for (int i = 0; i < R; ++i) {
          int x = root + width - R + i, y = root + width - R - 1 - i;
          int v = query(x) - query(x - 1);
          ;
          update(y, v);
        }
        root += width - R - 1, d = 1;
      } else {
        for (int i = 0; i < R; ++i) {
          int x = root - width + R - i, y = root - width + R + 1 + i;
          int v = query(x) - query(x - 1);
          ;
          update(y, v);
        }
        root += R + 1 - width, d = -1;
      }
      width = max(L, R);
      ;
    } else {
      int x, y;
      cin >> b;
      if (d == -1)
        x = root + a, y = root + b - 1;
      else
        x = root - a, y = root - b + 1;
      if (x > y) swap(x, y);
      ;
      int ans = query(y) - query(x - 1);
      cout << ans << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
