#include <bits/stdc++.h>
const int maxn = 100010;
using namespace std;
int N, n, q, cmd, p, l, r, sum[maxn], top, m[maxn], d;
void up(int pos, int val) {
  pos++;
  while (pos <= N) {
    sum[pos] += val;
    pos += pos & -pos;
  }
}
int read(int pos) {
  int ans = 0;
  pos++;
  while (pos) {
    ans += sum[pos];
    pos -= pos & -pos;
  }
  return ans;
}
int main() {
  int i, j, k;
  scanf("%d%d", &n, &q);
  N = n;
  for (i = 0; i < n; i++) {
    up(i, 1);
  }
  while (q--) {
    scanf("%d", &cmd);
    if (cmd == 1) {
      scanf("%d", &p);
      if (p > n - p) {
        d = !d;
        p = n - p;
      }
      if (d) {
        n = n - p;
        for (i = 0; i < p; i++)
          up(top + n - 1 - i, read(top + n + i) - read(top + n + i - 1));
      } else {
        top += p;
        for (i = 0; i < p; i++)
          up(top + i, read(top - 1 - i) - read(top - 2 - i));
        n -= p;
      }
    } else {
      scanf("%d%d", &l, &r);
      if (d)
        printf("%d\n", read(top + n - l - 1) - read(top + n - r - 1));
      else
        printf("%d\n", read(top + r - 1) - read(top + l - 1));
    }
  }
  return 0;
}
