#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 300009;
const int INF = 1e9;
const long long INF64 = 1e18;
const double eps = 1e-9;
const int MOD = 1e9 + 7;
int n, q;
int a[N], f[N];
int sum(int pos) {
  int res = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res += f[i];
  return res;
}
void upd(int pos, int d) {
  for (int i = pos; i < n; i |= i + 1) f[i] += d;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
int main() {
  cin >> n >> q;
  int l = 0, r = n - 1;
  bool rev = false;
  for (int i = 0; i < (int)(n); i++) {
    a[i] = 1;
    upd(i, 1);
  }
  for (int i = 0; i < (int)(q); i++) {
    int type, p, nl, nr;
    cin >> type;
    if (type == 1) {
      cin >> p;
      int len = r - l + 1;
      if (p * 2 <= len) {
        if (rev) {
          for (int i = r - p + 1, j = r - p; i <= r; ++i, --j) {
            upd(j, a[i]);
            upd(i, -a[i]);
            a[j] += a[i];
            a[i] = 0;
          }
          r -= p;
        } else {
          for (int i = l + p - 1, j = l + p; i >= l; --i, ++j) {
            upd(j, a[i]);
            upd(i, -a[i]);
            a[j] += a[i];
            a[i] = 0;
          }
          l += p;
        }
      } else {
        if (rev) {
          rev = false;
          p = len - p;
          for (int i = l + p - 1, j = l + p; i >= l; --i, ++j) {
            upd(j, a[i]);
            upd(i, -a[i]);
            a[j] += a[i];
            a[i] = 0;
          }
          l += p;
        } else {
          rev = true;
          p = len - p;
          for (int i = r - p + 1, j = r - p; i <= r; ++i, --j) {
            upd(j, a[i]);
            upd(i, -a[i]);
            a[j] += a[i];
            a[i] = 0;
          }
          r -= p;
        }
      }
    } else {
      cin >> nl >> nr;
      --nr;
      if (rev) {
        int ee = nr;
        nr = r - nl, nl = r - ee;
        cout << sum(nl, nr) << endl;
      } else {
        nl = l + nl, nr = l + nr;
        int xc = 0;
        cout << sum(nl, nr) << endl;
      }
    }
  }
  return 0;
}
