#include <bits/stdc++.h>
using namespace std;
int n, q, zero, width, rev;
int c[100005];
int lowbit(int x) { return x & -x; }
void add(int x, int val) {
  if (x <= 0) return;
  while (x <= 100001) {
    c[x] += val;
    x += lowbit(x);
  }
}
int sum(int x) {
  int r = 0;
  while (x) {
    r += c[x];
    x -= lowbit(x);
  }
  return r;
}
int main() {
  scanf("%d%d", &n, &q);
  width = n;
  rev = 1;
  for (int i = 1; i <= n; i++) add(i, 1);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int p;
      scanf("%d", &p);
      p = zero + p * rev;
      if (abs(p - zero) > abs(width - p)) {
        rev = -rev;
        swap(zero, width);
      }
      for (; zero != p; zero += rev) {
        int w = abs(sum(zero) - sum(zero + rev));
        add(p + (p - zero) + (rev == 1 ? 0 : 1), w);
      }
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      l = zero + l * rev, r = zero + r * rev;
      if (l > r) swap(l, r);
      printf("%d\n", sum(r) - sum(l));
    }
  }
  return 0;
}
