#include <bits/stdc++.h>
using namespace std;
int n, q;
int c[100010], a[100010];
int lowbit(int x) { return x & -x; }
int sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += c[x];
    x -= lowbit(x);
  }
  return ret;
}
void add(int x, int d) {
  while (x <= n) {
    c[x] += d;
    x += lowbit(x);
  }
}
int main() {
  scanf("%d%d", &n, &q);
  int left = 1, right = n;
  for (int i = 1; i <= n; ++i) {
    add(i, 1);
    a[i] = 1;
  }
  for (int i = 0; i < q; ++i) {
    int type, x, y;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &x);
      int len = abs(right - left) + 1;
      if (x > len - x) {
        swap(left, right);
        x = len - x;
      }
      if (left < right) {
        for (int j = 1; j <= x; ++j) {
          add(2 * x - j + left, a[left + j - 1]);
          a[2 * x - j + left] += a[left + j - 1];
        }
        left += x;
      } else {
        for (int j = 1; j <= x; ++j) {
          add(left - x - j + 1, a[left - x + j]);
          a[left - x - j + 1] += a[left - x + j];
        }
        left -= x;
      }
    } else {
      scanf("%d%d", &x, &y);
      if (left < right)
        printf("%d\n", sum(left + y - 1) - sum(left + x - 1));
      else
        printf("%d\n", sum(left - x) - sum(left - y));
    }
  }
  return 0;
}
