#include <bits/stdc++.h>
using namespace std;
bool read(int &tmp) {
  tmp = 0;
  int mark = 1;
  char ch = getchar();
  while (ch != EOF && isspace(ch)) ch = getchar();
  if (ch == EOF) return 0;
  if (ch == '-') mark = -1, ch = getchar();
  while (ch != EOF && (!isspace(ch))) tmp = tmp * 10 + ch - 48, ch = getchar();
  tmp = tmp * mark;
  return 1;
}
struct node {
  int size, data, sum;
  bool rev;
  node *l, *r, *fa;
  node() {
    size = data = sum = 1;
    l = r = fa = NULL;
    rev = 0;
  }
  void maintain() {
    size = 1;
    sum = data;
    if (l) size += l->size, sum += l->sum;
    if (r) size += r->size, sum += r->sum;
  }
} pool[110000 * 5], *cnt = pool, *root, *rootx, *rooty;
int n, q;
node *build(int l, int r) {
  int mid = l + r >> 1;
  if (l < mid) pool[mid].l = build(l, mid - 1), pool[mid].l->fa = &pool[mid];
  if (mid < r) pool[mid].r = build(mid + 1, r), pool[mid].r->fa = &pool[mid];
  pool[mid].maintain();
  return &pool[mid];
}
void turn_left(node *p) {
  node *q = p->fa;
  q->r = p->l;
  if (q->r) q->r->fa = q;
  q->maintain();
  if (q->fa) {
    if (q->fa->l == q)
      q->fa->l = p;
    else
      q->fa->r = p;
  }
  p->fa = q->fa;
  q->fa = p;
  p->l = q;
  p->maintain();
}
void turn_right(node *p) {
  node *q = p->fa;
  q->l = p->r;
  if (q->l) q->l->fa = q;
  q->maintain();
  if (q->fa) {
    if (q->fa->l == q)
      q->fa->l = p;
    else
      q->fa->r = p;
  }
  p->fa = q->fa;
  q->fa = p;
  p->r = q;
  p->maintain();
}
node *st[110000 * 2];
int top;
node *splay(node *p, node *tg) {
  top = 0;
  node *q, *r;
  for (q = p; q->fa != tg; q = q->fa) st[++top] = q;
  st[++top] = q;
  for (int i = top; i; i--)
    if (st[i]->rev) {
      r = st[i]->l;
      st[i]->l = st[i]->r;
      st[i]->r = r;
      if (st[i]->l) st[i]->l->rev ^= 1;
      if (st[i]->r) st[i]->r->rev ^= 1;
      st[i]->rev = 0;
    }
  while (p->fa != tg) {
    q = p->fa;
    if (q->fa == tg) {
      if (p == q->l)
        turn_right(p);
      else
        turn_left(p);
    } else {
      r = q->fa;
      if (q == r->l && p == q->l) {
        turn_right(q);
        turn_right(p);
        continue;
      }
      if (q == r->r && p == q->r) {
        turn_left(q);
        turn_left(p);
        continue;
      }
      if (q == r->l && p == q->r) {
        turn_left(p);
        turn_right(p);
        continue;
      }
      if (q == r->r && p == q->l) {
        turn_right(p);
        turn_left(p);
        continue;
      }
    }
  }
  if (tg == NULL) root = p;
  return p;
}
node *kth(node *p, int k) {
  if (p->rev) {
    node *r = p->l;
    p->l = p->r;
    p->r = r;
    if (p->l) p->l->rev ^= 1;
    if (p->r) p->r->rev ^= 1;
    p->rev = 0;
  }
  if (p->l) {
    if (p->l->size >= k) return kth(p->l, k);
    if (p->l->size + 1 == k) return p;
    return kth(p->r, k - p->l->size - 1);
  }
  if (k == 1) return p;
  return kth(p->r, k - 1);
}
node *join(node *x, node *y) {
  if (x == NULL) return NULL;
  if (x->size == 1) {
    x->data += y->data;
    x->sum += y->sum;
    return x;
  }
  int mid = x->size >> 1;
  node *rx = splay(kth(x, mid), x->fa);
  node *ry = splay(kth(y, mid), y->fa);
  rx->data += ry->data;
  rx->l = join(rx->l, ry->l);
  rx->r = join(rx->r, ry->r);
  rx->maintain();
  return rx;
}
node *merge(node *x, node *y) {
  if (x->size ^ y->size) {
    if (x->size < y->size) {
      node *p = x;
      x = y;
      y = p;
    }
    x = splay(kth(x, y->size + 1), NULL);
    x->l = join(x->l, y);
    x->maintain();
    return x;
  }
  return join(x, y);
}
int main() {
  read(n);
  root = build(1, n);
  read(q);
  for (int x, y, z, ans, i = 1; i <= q; i++) {
    read(x);
    if (x ^ 2) {
      read(y);
      splay(kth(root, y + 1), NULL);
      root->l->rev ^= 1;
      rootx = root->l;
      rooty = root;
      rooty->l = NULL;
      rootx->fa = NULL;
      rooty->maintain();
      root = merge(rootx, rooty);
    } else {
      read(y), read(z);
      if (y == 0 && z == root->size)
        ans = root->sum;
      else {
        if (y == 0) {
          splay(kth(root, z + 1), NULL);
          ans = root->l->sum;
        } else {
          if (z == root->size) {
            splay(kth(root, y), NULL);
            ans = root->r->sum;
          } else {
            splay(kth(root, z + 1), NULL);
            splay(kth(root, y), root);
            ans = root->l->r->sum;
          }
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
