#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
using namespace std;
struct node {
  node* l;
  node* r;
  int key;
  int prior;
  int size;
  int val;
  int maxx;
  bool rev;
};
node* create(int val, int pos) {
  node* x = new node;
  x->key = rand();
  x->l = NULL;
  x->r = NULL;
  x->prior = rand();
  x->size = 1;
  x->val = val;
  x->maxx = val;
  x->rev = 0;
  return x;
}
void pushdown(node* t) {
  if (!t || !t->rev) return;
  if (t->l) {
    t->l->rev = !(t->l->rev);
    swap(t->l->l, t->l->r);
  }
  if (t->r) {
    t->r->rev = !(t->r->rev);
    swap(t->r->l, t->r->r);
  }
  t->rev = 0;
}
int sz(node* x) { return x ? x->size : 0; }
void upd_sz(node* x) {
  if (x) x->size = sz(x->l) + sz(x->r) + 1;
}
int retmax(node* x) { return x ? x->maxx : 0; }
void upd_max(node* x) {
  if (x) x->maxx = retmax(x->l) + retmax(x->r) + x->val;
}
void printtreap(node* t) {
  pushdown(t);
  if (!t) return;
  printtreap(t->l);
  cout << t->val << " ";
  printtreap(t->r);
}
void split(node* t, node*& left, node*& right, int key, int add = 0) {
  if (!t) {
    left = right = NULL;
    return;
  }
  int curpos = add + sz(t->l);
  pushdown(t);
  if (curpos <= key)
    split(t->r, t->r, right, key, curpos + 1), left = t;
  else
    split(t->l, left, t->l, key, add), right = t;
  upd_sz(t);
  upd_max(t);
}
void merge(node*& t, node* l, node* r) {
  pushdown(l);
  pushdown(r);
  if (!l)
    t = r;
  else if (!r)
    t = l;
  else if (l->prior > r->prior)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
  upd_sz(t);
  upd_max(t);
}
void insert(node*& t, int x, int y) {
  pushdown(t);
  node* tmp = create(y, x);
  node* lll;
  node* lll2;
  node* rrr;
  node* kutta;
  node* del;
  split(t, lll, rrr, x);
  split(lll, lll2, del, x - 1);
  merge(kutta, lll2, tmp);
  merge(t, kutta, rrr);
}
void reverse(node* t) {
  if (!t) return;
  swap(t->l, t->r);
  t->rev = !t->rev;
  return;
}
int query(node*& t, int l, int r, int x) {
  if (!t) return 0;
  node *le, *ri, *mid, *midd;
  split(t, le, mid, l - 1);
  split(mid, midd, ri, r - l);
  int ans;
  if (midd == NULL)
    ans = 0;
  else
    ans = midd->maxx;
  merge(mid, midd, ri);
  merge(t, le, mid);
  return ans;
}
int main() {
  node* treap = NULL;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    insert(treap, i, 1);
  }
  int curwid = n;
  for (int i = 0; i < m; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int p;
      cin >> p;
      int left = p;
      int right = curwid - p;
      assert(right > 0);
      if (left <= right) {
        for (int i = 0; i < left; ++i) {
          int wen = query(treap, left - i - 1, left - i - 1, 0);
          int old = query(treap, left + i, left + i, 0);
          insert(treap, left + i, wen + old);
        }
        curwid = right;
        node* le;
        node* ri;
        split(treap, le, ri, left - 1);
        treap = ri;
      } else {
        for (int i = 0; i < right; ++i) {
          int wen = query(treap, left + i, left + i, 0);
          int old = query(treap, left - i - 1, left - i - 1, 0);
          insert(treap, left - i - 1, wen + old);
        }
        curwid = left;
        node* le;
        node* ri;
        split(treap, le, ri, left - 1);
        treap = le;
        reverse(treap);
      }
    } else {
      int l, r;
      cin >> l >> r;
      int x = sz(treap);
      int flag = 0;
      int ans = query(treap, l, r - 1, flag);
      assert(x == sz(treap));
      cout << ans << "\n";
    }
  }
}
