#include <bits/stdc++.h>
int p[100100];
void solve(int n, int m) {
  int i, j, k, x, s = 0, l = 0, r = n;
  for (i = 0; i < 100100; i++) p[i] = 0;
  for (i = 0; i <= n; i++) p[i] = i;
  for (k = 0; k < m; k++) {
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &x);
      if (s == 0) {
        if (2 * x <= r - l) {
          for (i = l + x; i <= l + 2 * x; i++)
            p[i] = p[i] - p[2 * l + 2 * x - i];
          l += x;
        } else {
          for (i = l + x; i >= 2 * l + 2 * x - r; i--)
            p[i] = p[i] + n - p[2 * l + 2 * x - i];
          r -= r - l - x;
          s = 1;
        }
      } else {
        if (2 * x <= r - l) {
          x = r - l - x;
          for (i = l + x; i >= 2 * l + 2 * x - r; i--)
            p[i] = p[i] + n - p[2 * l + 2 * x - i];
          r -= r - l - x;
        } else {
          x = r - l - x;
          for (i = l + x; i <= l + 2 * x; i++)
            p[i] = p[i] - p[2 * l + 2 * x - i];
          l += x;
          s = 0;
        }
      }
    } else {
      scanf("%d%d", &i, &j);
      if (s == 0) {
        printf("%d\n", p[j + l] - p[i + l]);
      } else {
        printf("%d\n", p[r - i] - p[r - j]);
      }
    }
  }
}
int main() {
#pragma comment(linker, "/STACK:134217728")
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    solve(n, m);
    printf("\n");
  }
  return 0;
}
