#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;
long long seg[3 * NN], lazy[3 * NN];
void join(int node) { seg[node] = (seg[2 * node] + seg[2 * node + 1]); }
void build(int node, int st, int en) {
  if (st == en) {
    seg[node] = 1LL;
    lazy[node] = 0LL;
    return;
  }
  int mid = (st + en) / 2;
  build(2 * node, st, mid);
  build(2 * node + 1, mid + 1, en);
  join(node);
}
void pushdown(int node, int st, int en) {
  if (!lazy[node]) return;
  seg[node] += lazy[node];
  if (st != en) lazy[2 * node] += lazy[node], lazy[2 * node + 1] += lazy[node];
  lazy[node] = 0;
}
void update(int node, int st, int en, int L, int R, long long add) {
  if (L > R) swap(L, R);
  pushdown(node, st, en);
  if (st > R or en < L) return;
  if (st >= L and en <= R) {
    lazy[node] += add;
    pushdown(node, st, en);
    return;
  }
  int mid = (st + en) / 2;
  update(2 * node, st, mid, L, R, add);
  update(2 * node + 1, mid + 1, en, L, R, add);
  join(node);
}
long long query(int node, int st, int en, int L, int R) {
  pushdown(node, st, en);
  if (L > R) swap(L, R);
  if (st > R or en < L) return 0;
  if (st >= L and en <= R) return seg[node];
  int mid = (st + en) / 2;
  long long ans =
      (query(2 * node, st, mid, L, R) + query(2 * node + 1, mid + 1, en, L, R));
  return ans;
}
void solve() {
  int n, m;
  cin >> n >> m;
  build(1, 0, n - 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;
          long long v = query(1, 0, n - 1, x, x);
          ;
          update(1, 0, n - 1, y, 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;
          long long v = query(1, 0, n - 1, x, x);
          ;
          update(1, 0, n - 1, y, 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;
          long long v = query(1, 0, n - 1, x, x);
          ;
          update(1, 0, n - 1, y, 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;
          long long v = query(1, 0, n - 1, x, x);
          ;
          update(1, 0, n - 1, y, 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;
      ;
      long long ans = query(1, 0, n - 1, x, y);
      cout << ans << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
