#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 10;
struct Node {
  int y;
  int val;
  Node *l, *r;
  int sz;
  long long sum = 0;
  Node(int val = '\0', int y = 0, Node *l = 0, Node *r = 0)
      : val(val), y(y), l(l), r(r) {
    sz = 1;
    sum = 0;
  }
};
typedef Node *Treap;
Node _buf_Node[int(1e6)];
int _buf_Node_size = 0;
Treap t;
int n, q;
bool is_reverse = 0;
Treap newNode() { return &_buf_Node[_buf_Node_size++]; }
int rnd() { return rand() ^ (rand() << 16); }
void resize(Treap &t) {
  if (t == NULL) return;
  t->sz = 1;
  if (t->l) t->sz += t->l->sz;
  if (t->r) t->sz += t->r->sz;
}
void print_treap(Treap t) {
  if (t == NULL) return;
  print_treap(t->l);
  cout << t->val << ' ';
  print_treap(t->r);
}
void resum(Treap &t) {
  if (t == NULL) return;
  t->sum = t->val;
  if (t->r != NULL) t->sum += t->r->sum;
  if (t->l != NULL) t->sum += t->l->sum;
}
void split(Treap t, int x, Treap &l, Treap &r) {
  if (!t) {
    l = r = NULL;
    return;
  }
  int cnt_left = 0;
  if (t->l != NULL) cnt_left = t->l->sz;
  if (x <= cnt_left) {
    split(t->l, x, l, t->l);
    r = t;
  } else {
    split(t->r, x - 1 - cnt_left, t->r, r);
    l = t;
  }
  resum(t);
  resize(t);
}
Treap merge(Treap &a, Treap &b) {
  if (!a || !b) return max(a, b);
  Treap new_node;
  if (a->y > b->y) {
    new_node = a;
    new_node->r = merge(new_node->r, b);
  } else {
    new_node = b;
    new_node->l = merge(a, new_node->l);
  }
  resum(new_node);
  resize(new_node);
  return new_node;
}
void add_to_end(Treap &t, int val) {
  Treap new_treap = newNode();
  new_treap->val = val;
  new_treap->y = rnd();
  new_treap->sum = val;
  resize(new_treap);
  t = merge(t, new_treap);
}
void add_to_k(Treap &t, int pos, int add) {
  int cnt_left = 0;
  if (t->l != NULL) cnt_left = t->l->sz;
  if (pos == cnt_left + 1) {
    t->val += add;
    resum(t);
    return;
  }
  if (pos <= cnt_left)
    add_to_k(t->l, pos, add);
  else
    add_to_k(t->r, pos - cnt_left - 1, add);
  resum(t);
}
long long get_sum(Treap &t, int l, int r) {
  Treap b = 0, c = 0;
  split(t, r, b, c);
  Treap a = 0, d = 0;
  split(b, l, a, d);
  long long res = d->sum;
  b = merge(a, d);
  t = merge(b, c);
  return res;
}
int go_add_x = 1;
void go_add_treap(Treap &a, int add) {
  if (a == NULL) return;
  go_add_treap(a->l, add);
  add_to_k(t, go_add_x, a->val);
  go_add_x += add;
  go_add_treap(a->r, add);
}
void cmd_1(Treap &t, int x) {
  int left = x;
  int right = t->sz - x;
  Treap a = 0, b = 0;
  split(t, x, a, b);
  if (left < right) {
    t = b;
    if (is_reverse == 1) is_reverse = 0;
    go_add_x = a->sz;
    go_add_treap(a, -1);
    t = b;
  } else {
    t = a;
    if (is_reverse == 0) is_reverse = 1;
    go_add_x = t->sz;
    go_add_treap(b, -1);
  }
}
void task() {
  ios_base::sync_with_stdio(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i) add_to_end(t, 1);
  while (q--) {
    int cmd;
    cin >> cmd;
    if (cmd == 1) {
      int x;
      cin >> x;
      if (is_reverse) x = t->sz - x;
      cmd_1(t, x);
    } else {
      int l, r;
      cin >> l >> r;
      if (is_reverse) {
        l = t->sz - l;
        r = t->sz - r;
        swap(l, r);
      }
      cout << get_sum(t, l, r) << "\n";
    }
  }
}
int main() {
  task();
  return 0;
}
