#include <bits/stdc++.h>
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
using namespace std;
constexpr int inf = 1e9 + 7, base = 541;
constexpr long long mod = 1e9 + 7, N = 1e6 + 7, X = 1e10 + 7;
int n, Q, st, en, rev;
struct node {
  int l, r, a;
  node() { l = -1, r = -1, a = 0; }
} sum[5 * N];
int cur = 2;
inline void make(int tag) {
  if (sum[tag].l == -1) {
    sum[tag].l = cur++;
    sum[tag].r = cur++;
  }
}
inline void update(int pos, int nw, int tag = 1, long long s = 0,
                   long long e = X) {
  if (e == s + 1) {
    sum[tag].a += nw;
    return;
  }
  long long mid = (s + e) / 2ll;
  make(tag);
  if (pos < mid)
    update(pos, nw, sum[tag].l, s, mid);
  else
    update(pos, nw, sum[tag].r, mid, e);
  sum[tag].a = sum[sum[tag].l].a + sum[sum[tag].r].a;
}
inline int query(int l, int r, int tag = 1, long long s = 0, long long e = X) {
  if (s >= r || e <= l) return 0;
  if (s >= l && e <= r) {
    return sum[tag].a;
  }
  make(tag);
  long long mid = (s + e) / 2;
  return query(l, r, sum[tag].l, s, mid) + query(l, r, sum[tag].r, mid, e);
}
int32_t main() {
  cin >> n >> Q;
  for (int(i) = (0); (i) < (n); ++(i)) update(i, 1);
  en = n;
  while (Q--) {
    int type, l, r, pos;
    cin >> type;
    if (type == 1) {
      cin >> pos;
      l = en - st;
      if (pos > l - pos) rev ^= 1, pos = l - pos;
      if (!rev) {
        for (int(i) = (0); (i) < (pos); ++(i))
          update(st + (pos - i - 1) + pos, query(st + i, 1 + st + i));
        st += pos;
      } else {
        for (int(i) = (0); (i) < (pos); ++(i))
          update(en - pos - (pos - i), query(en - 1 - i, en - i));
        en -= pos;
      }
    } else {
      l = in();
      r = in();
      if (!rev)
        l += st + 1, r += st;
      else
        l = en - l, r = en - r + 1;
      cout << query(min(l, r) - 1, max(l, r)) << endl;
    }
  }
}
