#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int maxn = 100005;
long long t[maxn];
void inc(int i, long long x) {
  while (i < maxn) {
    t[i] += x;
    i = i | (i + 1);
  }
}
long long sum(long long r) {
  long long res = 0;
  while (r >= 0) {
    res += t[r];
    r = (r & (r + 1)) - 1;
  }
  return res;
}
int main(int argc, char *argv[]) {
  int n, q;
  scanf("%d %d", &n, &q);
  int l = 0, r = n - 1;
  bool inv = false;
  for (int i = 0; i < n; i++) inc(i, 1);
  for (int i = 0; i < q; i++) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x;
      scanf("%d", &x);
      if (!inv) {
        if (r - l + 1 - x >= x) {
          for (int j = 0; j < x; j++) {
            long long y = sum(j + l) - sum(j + l - 1);
            inc(l + x + x - 1 - j, y);
          }
          l += x;
        } else {
          x = r - l + 1 - x;
          for (int j = 0; j < x; j++) {
            long long y = sum(r - j) - sum(r - j - 1);
            inc(r - x - x + 1 + j, y);
          }
          r -= x;
          inv = true;
        }
      } else {
        if (r - l + 1 - x >= x) {
          for (int j = 0; j < x; j++) {
            long long y = sum(r - j) - sum(r - j - 1);
            inc(r - x - x + 1 + j, y);
          }
          r -= x;
        } else {
          x = r - l + 1 - x;
          for (int j = 0; j < x; j++) {
            long long y = sum(l + j) - sum(l + j - 1);
            inc(l + x + x - 1 - j, y);
          }
          inv = false;
          l += x;
        }
      }
    } else {
      int u, v;
      scanf("%d %d", &v, &u);
      if (!inv) {
        cout << sum(l + u - 1) - sum(l + v - 1) << endl;
      } else {
        cout << sum(r - v) - sum(r - u) << endl;
      }
    }
  }
  return 0;
}
