#include <bits/stdc++.h>
int n;
int thick[100002];
void add(int x, int c) {
  do thick[x] += c;
  while ((x += ((x) & -(x))) <= n);
}
int sum(int x) {
  int ans = 0;
  do ans += thick[x];
  while ((x -= ((x) & -(x))));
  return ans;
}
int main() {
  int q, p, l, r, begin, end, flag, i;
  while (scanf("%d%d", &n, &q) > 0) {
    memset(thick, 0, sizeof(thick));
    for (i = 1, begin = 0, end = n, flag = 0; i <= n; i++) add(i, 1);
    while (q-- && scanf("%d", &p))
      if (p < 2) {
        scanf("%d", &r);
        r = flag ? end - r : begin + r;
        if (r << 1 > begin + end) {
          for (i = r; i < end; i++) add(r + r - i, sum(i + 1) - sum(i));
          end = r;
          flag = 1;
        } else {
          for (i = begin; i < r; i++) add(r + r - i, sum(i + 1) - sum(i));
          begin = r;
          flag = 0;
        }
      } else {
        scanf("%d%d", &l, &r);
        i = l;
        l = flag ? end - r : begin + l;
        r = flag ? end - i : begin + r;
        printf("%d\n", sum(r) - sum(l));
      }
  }
  return 0;
}
