#include <bits/stdc++.h>
using namespace std;
int segtree[2 * 100010];
int getid(int l, int r) { return l + r | l != r; }
void build(int l, int r) {
  int id = getid(l, r);
  segtree[id] = (r - l) + 1;
  if (l == r) return;
  int m = (l + r) >> 1;
  build(l, m);
  build(m + 1, r);
}
void upd(int l, int r) {
  int id = getid(l, r), m = (l + r) >> 1;
  int lid = getid(l, m), rid = getid(m + 1, r);
  segtree[id] = segtree[lid] + segtree[rid];
}
void update(int l, int r, int c, int pos) {
  int id = getid(l, r);
  if (l == r && l == pos)
    segtree[id] += c;
  else if (l <= pos && pos <= r) {
    int m = (l + r) >> 1;
    update(l, m, c, pos);
    update(m + 1, r, c, pos);
    upd(l, r);
  }
}
int query(int l, int r, int ll, int rr) {
  if (l != r) upd(l, r);
  int ans = 0;
  int id = getid(l, r);
  if (ll <= l && r <= rr)
    ans = segtree[id];
  else if (l <= rr && ll <= r) {
    int m = (l + r) >> 1;
    ans += query(l, m, ll, rr) + query(m + 1, r, ll, rr);
  }
  return ans;
}
int main() {
  int n, q, type, pos, l, r, head = 1, ans, hh, t;
  bool reverse = false;
  scanf("%d%d", &n, &q);
  build(head, n);
  hh = head;
  t = n;
  while (q--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &pos);
      if (reverse == false) {
        if (2 * pos > (n - head + (((n - head) % 2 == 0) ? 0 : 1)))
          reverse = !(reverse);
        if (2 * pos <= (n - head + (((n - head) % 2 == 0) ? 0 : 1))) {
          for (int i = 1; i <= pos; i++) {
            update(hh, t, segtree[getid(head + i - 1, head + i - 1)],
                   head + 2 * pos - i);
            update(hh, t, -segtree[getid(head + i - 1, head + i - 1)],
                   head + i - 1);
          }
          head += pos;
        } else {
          for (int i = 1; i <= n - pos - head + 1; i++) {
            update(hh, t, segtree[getid(n - i + 1, n - i + 1)],
                   n - 2 * (n - pos - head + 1) + i);
            update(hh, t, -segtree[getid(n - i + 1, n - i + 1)], n - i + 1);
          }
          n = (pos + head - 1);
        }
      } else {
        if (2 * pos > (n - head + (((n - head) % 2 == 0) ? 0 : 1)))
          reverse = !(reverse);
        if (2 * pos <= (n - head + (((n - head) % 2 == 0) ? 0 : 1))) {
          for (int i = 1; i <= pos; i++) {
            update(hh, t, segtree[getid(n - i + 1, n - i + 1)],
                   n - 2 * pos + i);
            update(hh, t, -segtree[getid(n - i + 1, n - i + 1)], n - i + 1);
          }
          n -= pos;
        } else {
          for (int i = 1; i <= n - pos - head + 1; i++) {
            update(hh, t, segtree[getid(head + i - 1, head + i - 1)],
                   head + 2 * (n - pos - head + 1) - i);
            update(hh, t, -segtree[getid(head + i - 1, head + i - 1)],
                   head + i - 1);
          }
          head = (n - pos + 1);
        }
      }
    } else {
      scanf("%d%d", &l, &r);
      if (reverse == false)
        ans = query(hh, t, head + l, head + r - 1);
      else
        ans = query(hh, t, n - r + 1, n - l);
      printf("%d\n", ans);
    }
  }
  return 0;
}
