#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int n, q, BASE;
int psum[MAX_N];
bool rev;
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) psum[i] = i;
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x;
      scanf("%d", &x);
      if (rev) x = n - x;
      if (x <= n - x) {
        for (int i = x + x; x < i; i--)
          psum[BASE + i] -= psum[BASE + x - (i - x)];
        for (int i = 1; i <= x; i++) psum[BASE + i] = 0;
        if (rev == true) rev = false;
        BASE += x;
        n = n - x;
      } else {
        for (int i = x - (n - x); i <= x; i++)
          psum[BASE + i] += psum[BASE + n] - psum[BASE + x + (x - i)];
        if (rev == false) rev = true;
        for (int i = x + 1; i <= n; i++) psum[BASE + i] = 0;
        n = x;
      }
    } else {
      int x1, x2;
      scanf("%d %d", &x1, &x2);
      if (!rev)
        printf("%d\n", psum[BASE + x2] - psum[BASE + x1]);
      else
        printf("%d\n", psum[BASE + n - x1] - psum[BASE + n - x2]);
    }
  }
  return 0;
}
