#include <bits/stdc++.h>
const int N = 100000 + 5;
int ran() {
  static int ranx = 123654987;
  return ranx += ranx << 2 | 1;
}
struct Node *nill;
struct Node {
  Node *ch[2];
  int sz, v, mx, rd, sum;
  bool rev;
  void re() {
    std::swap(ch[0], ch[1]);
    rev ^= 1;
  }
  void up() {
    if (this == nill) return;
    sz = 1 + ch[0]->sz + ch[1]->sz;
    mx = std::max(v, std::max(ch[0]->mx, ch[1]->mx));
    sum = v + ch[0]->sum + ch[1]->sum;
  }
  void down() {
    if (rev) {
      ch[0]->re();
      ch[1]->re();
      rev = false;
    }
  }
  void show() {
    if (this == nill) return;
    down();
    ch[0]->show();
    printf("%d ", v);
    ch[1]->show();
  }
} pool[N], *bat, *root;
void cut(Node *a, Node *&b, Node *&c, int K) {
  if (a->sz == K) {
    b = a;
    c = nill;
  } else if (K == 0) {
    b = nill;
    c = a;
  } else if (a->ch[0]->sz >= K) {
    a->down();
    c = a;
    cut(a->ch[0], b, c->ch[0], K);
    c->up();
  } else {
    a->down();
    b = a;
    cut(a->ch[1], b->ch[1], c, K - a->ch[0]->sz - 1);
    b->up();
  }
}
void merge(Node *&a, Node *b, Node *c) {
  if (b == nill) {
    a = c;
  } else if (c == nill) {
    a = b;
  } else if (b->rd > c->rd) {
    b->down();
    a = b;
    merge(a->ch[1], b->ch[1], c);
    a->up();
  } else {
    c->down();
    a = c;
    merge(a->ch[0], b, c->ch[0]);
    a->up();
  }
}
void show(Node *o) {
  printf("=.=");
  o->show();
  puts("");
}
void newNode(Node *&o, int val = 0) {
  o = bat++;
  o->ch[0] = o->ch[1] = nill;
  o->rev = false;
  o->sz = 1;
  o->mx = o->v = o->sum = val;
  o->rd = ran();
}
void init() {
  bat = pool;
  newNode(nill);
  nill->sz = 0;
  root = nill;
}
void build(Node *&o, int n) {
  if (n == 0) return;
  newNode(o, 1);
  build(o->ch[0], n >> 1);
  build(o->ch[1], n - 1 - (n >> 1));
  o->up();
}
void flatten(Node *o, std::vector<int> &adds) {
  if (o == nill) return;
  o->down();
  flatten(o->ch[0], adds);
  adds.push_back(o->v);
  flatten(o->ch[1], adds);
}
void modify(Node *o, int base, std::vector<int> &adds) {
  if (o == nill) return;
  o->down();
  if (adds.size() <= o->ch[0]->sz + base) {
    modify(o->ch[0], base, adds);
  } else {
    o->v += adds[o->ch[0]->sz + base];
    modify(o->ch[0], base, adds);
    modify(o->ch[1], base + o->ch[0]->sz + 1, adds);
  }
  o->up();
}
void modify(int pos) {
  Node *a, *b, *c;
  cut(root, a, b, pos);
  a->re();
  std::vector<int> adds;
  if (a->sz <= b->sz) {
    flatten(a, adds);
    modify(b, 0, adds);
    root = b;
  } else {
    flatten(b, adds);
    modify(a, 0, adds);
    root = a;
  }
}
int query(int l, int r) {
  Node *a, *b, *c;
  cut(root, a, b, l);
  cut(b, b, c, r - l);
  int ret = b->sum;
  merge(b, b, c);
  merge(root, a, b);
  return ret;
}
int main() {
  int n, nq;
  scanf("%d%d", &n, &nq);
  init();
  build(root, n);
  while (nq--) {
    int op, a, b;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d", &a);
      modify(a);
    } else {
      scanf("%d%d", &a, &b);
      printf("%d\n", query(a, b));
    }
  }
  return 0;
}
