#include <bits/stdc++.h>
int n, q;
int L, R;
int t[300005];
int s[100005];
int a, b;
bool is;
void build(int l, int r, int d) {
  if (l == r) {
    t[d] = 1;
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, d * 2);
  build(mid + 1, r, d * 2 + 1);
  t[d] = t[d * 2] + t[d * 2 + 1];
}
void insert(int l, int r, int d, int x, int data) {
  if (x < l || x > r) return;
  if (l == r && l == x) {
    t[d] += data;
    return;
  }
  int mid = (l + r) / 2;
  insert(l, mid, d * 2, x, data);
  insert(mid + 1, r, d * 2 + 1, x, data);
  t[d] = t[d * 2] + t[d * 2 + 1];
  return;
}
void modify(int x) {
  int len = R + 1 - L;
  if (x > len / 2) {
    is = !is;
    x = len - x;
  }
  if (is) {
    for (int i = L, j = L + x + x - 1; i < L + x; i++, j--) {
      insert(0, n - 1, 1, i, -s[i]);
      insert(0, n - 1, 1, j, s[i]);
      s[j] += s[i];
      s[i] = 0;
    }
    L += x;
  } else {
    for (int i = R, j = R - x - x + 1; i > R - x; i--, j++) {
      insert(0, n - 1, 1, i, -s[i]);
      insert(0, n - 1, 1, j, s[i]);
      s[j] += s[i];
      s[i] = 0;
    }
    R -= x;
  }
}
int find(int l, int r, int a, int b, int d) {
  if (b < l || a > r) return 0;
  if (a <= l && r <= b) return t[d];
  int mid = (l + r) / 2;
  return find(l, mid, a, b, d * 2) + find(mid + 1, r, a, b, d * 2 + 1);
}
void ch(int l, int r, int d) {
  if (l == r) {
    printf("%d ", t[d]);
    return;
  }
  int mid = (l + r) / 2;
  ch(l, mid, d * 2);
  ch(mid + 1, r, d * 2 + 1);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) s[i] = 1;
  L = 0;
  R = n - 1;
  is = 1;
  build(0, n - 1, 1);
  while (q--) {
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d", &a);
      modify(a);
    } else {
      scanf("%d%d", &a, &b);
      if (is) {
        printf("%d\n", find(0, n - 1, L + a, L + b - 1, 1));
      } else {
        printf("%d\n", find(0, n - 1, R - b + 1, R - a, 1));
      }
    }
  }
  return 0;
}
