#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int c[MAXN], s[MAXN], n;
void ADD(int p, int val) {
  s[p] += val;
  while (p <= n) {
    c[p] += val;
    p += ((p) & (-(p)));
  }
}
int getsum(int p) {
  int sum = 0;
  while (p > 0) {
    sum += c[p];
    p -= ((p) & (-(p)));
  }
  return sum;
}
int main() {
  int i, p;
  scanf("%d%d", &n, &p);
  memset(c, 0, sizeof(c));
  memset(s, 0, sizeof(s));
  for (i = 1; i <= n; ++i) ADD(i, 1);
  int l = 1, r = n;
  int x, y, z;
  int flag = 0;
  for (int k = 0; k < p; ++k) {
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &y);
      int fg = ((y * 2) > (r - l + 1));
      int mid;
      if (flag)
        mid = r - y;
      else
        mid = l + y - 1;
      int ll = mid - l + 1;
      int rr = r - mid;
      if (ll <= rr) {
        for (i = l; i <= mid; ++i) ADD(2 * mid + 1 - i, s[i]);
        l = mid + 1;
      } else {
        for (i = mid + 1; i <= r; ++i) ADD(2 * mid + 1 - i, s[i]);
        r = mid;
      }
      flag ^= fg;
    } else {
      scanf("%d%d", &y, &z);
      if (flag)
        printf("%d\n", getsum(r - y) - getsum(r - z));
      else
        printf("%d\n", getsum(l + z - 1) - getsum(l + y - 1));
    }
  }
  return 0;
}
