#include <bits/stdc++.h>
using namespace std;
char BUFFER[100000 + 5];
bool readn(int &n) { return scanf("%d", &n) == 1; }
bool readl(long long &n) { return scanf("%I64d", &n) == 1; }
bool readd(double &n) { return scanf("%lf", &n) == 1; }
bool reads(string &s) {
  s = "";
  int n = scanf("%s", BUFFER);
  if (n == 1) s = BUFFER;
  return n == 1;
}
bool readln(string &s) {
  char *valid = gets(BUFFER);
  if (valid) s = BUFFER;
  return ((bool)valid);
}
const int maxn = 1e5 + 10;
int v[maxn], sum[maxn];
void add(int x, int val) {
  v[x] += val;
  while (x < maxn) {
    sum[x] += val;
    x += (x & (-x));
  }
}
int query(int x) {
  int su = 0;
  while (x) {
    su += sum[x];
    x -= (x & (-x));
  }
  return su;
}
int main() {
  int i, n, p, q, t, a, b, src, dst;
  bool reversed = false;
  cin >> n >> q;
  memset((sum), (0), sizeof(sum));
  memset((v), (0), sizeof(v));
  for (i = 1; i < n + 1; ++i) add(i, 1);
  src = 0;
  dst = n;
  while (q--) {
    n = dst - src;
    cin >> t;
    if (1 == t) {
      cin >> p;
      if (reversed) p = n - p;
      if (2 * p <= n) {
        for (i = src; i < src + p; ++i) add(2 * (src + p) - i, v[i + 1]);
        src += p;
        reversed = false;
      } else {
        for (i = src + p; i < dst; ++i) add(2 * (src + p) - i, v[i + 1]);
        dst = src + p;
        reversed = true;
      }
    } else {
      cin >> a >> b;
      if (reversed) {
        a = n - a;
        b = n - b;
        swap(a, b);
      }
      cout << query(src + b) - query(src + a) << endl;
    }
  }
  return 0;
}
