#include <bits/stdc++.h>
using namespace std;
int tree[100005] = {0};
int n;
void update(int x, int val) {
  while (x <= n) {
    tree[x] += val;
    x += (x & -x);
  }
}
int read(int x) {
  int s = 0;
  while (x > 0) {
    s += tree[x];
    x -= (x & -x);
  }
  return s;
}
int beg, enn;
bool inv = 0;
int ar[100005];
int query(int l, int r) {
  ++l;
  if (inv) {
    int en = enn - beg + 1;
    r = en - r + 1;
    l = en - l + 1;
    if (r < l) swap(l, r);
  }
  l += beg - 1, r += beg - 1;
  return read(r) - read(l - 1);
}
int main() {
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) update(i, 1), ar[i] = 1;
  beg = 1, enn = n;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int pi;
      cin >> pi;
      if (pi > (enn - beg + 1) / 2) {
        inv = !inv;
        pi = enn - beg + 1 - pi;
      }
      if (!inv) {
        pi += beg - 1;
        int nbeg = pi + 1;
        int i = pi + 1;
        while (pi >= beg) {
          int vv = read(pi--) - read(pi);
          ar[i] += vv;
          update(i++, vv);
        }
        beg = nbeg;
      } else {
        int en = enn - beg + 1;
        pi = en - pi + 1;
        pi += beg - 1;
        int nen = pi - 1;
        int i = pi - 1;
        while (pi <= enn) {
          int vv = read(pi) - read(pi - 1);
          ar[i] += vv;
          update(i--, vv);
          ++pi;
        }
        enn = nen;
      }
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(l, r) << endl;
    }
  }
}
