#include <bits/stdc++.h>
using namespace std;
int recur_depth = 0;
const long long sz = 1e5 + 10;
long long BIT[sz];
void upd(long long idx, long long v, long long n) {
  while (idx <= n) {
    BIT[idx] += v;
    idx += idx & (-idx);
  }
}
long long getSum(long long idx) {
  long long ret = 0;
  while (idx > 0) {
    ret += BIT[idx];
    idx -= idx & (-idx);
  }
  return ret;
}
inline long long qry(long long l, long long r) {
  return getSum(r) - getSum(l - 1);
}
int main() {
  long long n, q;
  cin >> n >> q;
  for (long long i = 1; i <= n; ++i) upd(i, 1, n);
  long long start = 0, stop = n, rev = 0;
  while (q--) {
    long long op;
    scanf("%lld", &op);
    if (op == 1) {
      long long p;
      scanf("%lld", &p);
      long long len = stop - start;
      if (p > len - p) {
        p = len - p;
        rev ^= 1;
      }
      if (!rev) {
        for (long long i = start + 1, j = start + p + p; i <= start + p;
             i++, j--) {
          long long got = qry(i, i);
          upd(j, got, n);
        }
        start += p;
      } else {
        for (long long i = stop, j = stop - p - p + 1; i > stop - p; i--, j++) {
          long long got = qry(i, i);
          upd(j, got, n);
        }
        stop -= p;
      }
    } else {
      long long l, r;
      scanf("%lld", &l), scanf("%lld", &r);
      l += start, r += start;
      if (!rev)
        printf("%lld\n", qry(l + 1, r));
      else {
        l = stop - l + start, r = stop - r + start;
        swap(l, r);
        printf("%lld\n", qry(l + 1, r));
      }
    }
  }
  return 0;
}
