#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
const int offset = 1 << 18;
struct tournament {
  int data[2 * offset];
  void set(int x, int v) {
    data[x += offset] += v;
    for (x /= 2; x; x /= 2) data[x] = data[2 * x] + data[2 * x + 1];
  }
  int get(int x, int lo, int hi, int from, int to) {
    if (lo >= to || hi <= from) return 0;
    if (lo >= from && hi <= to) return data[x];
    int mid = (lo + hi) / 2;
    return get(2 * x, lo, mid, from, to) + get(2 * x + 1, mid, hi, from, to);
  }
} T;
int n, q;
int s[MAXN];
void update(int x, int &rev, int &start, int &end) {
  if (2 * x > end - start) {
    rev ^= 1;
    x = end - x - start;
  }
  if (rev) {
    for (int i = end - x, j = i - 1; i < end; --j, ++i) {
      s[j] += s[i];
      T.set(j, s[i]);
    }
    end -= x;
  } else {
    for (int i = start + x, j = i - 1; j >= start; --j, ++i) {
      s[i] += s[j];
      T.set(i, s[j]);
    }
    start += x;
  }
}
int query(int l, int r, int rev, int start, int end) {
  if (rev) return T.get(1, 0, offset, end - r, end - l);
  return T.get(1, 0, offset, l + start, r + start);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i) {
    s[i] = 1;
    T.set(i, 1);
  }
  int rev = 0;
  int start = 0, end = n;
  for (int ii = 0; ii < q; ++ii) {
    int tip, l, r;
    scanf("%d", &tip);
    if (tip == 1) {
      scanf("%d", &l);
      update(l, rev, start, end);
    } else {
      scanf("%d%d", &l, &r);
      printf("%d\n", query(l, r, rev, start, end));
    }
  }
  return 0;
}
