#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (decltype((v).begin()) i = (v).begin(); i != (v).end(); ++i) {
    if (i != (v).begin()) os << ", ";
    os << *i;
  }
  os << "]";
  return os;
}
vector<int> seg_tree, paper;
int n, q, l, r;
bool flipped = false;
void build(int v, int ll, int rr) {
  if (ll == rr)
    seg_tree[v] = paper[ll];
  else {
    int temp = (ll + rr) >> 1;
    build(v << 1, ll, temp);
    build((v << 1) + 1, temp + 1, rr);
    seg_tree[v] = seg_tree[v << 1] + seg_tree[(v << 1) + 1];
  }
}
int sum(int v, int ll, int rr, int lb, int rb) {
  if (rr < lb || ll > rb) return 0;
  if (lb <= ll && rr <= rb) return seg_tree[v];
  int temp = (ll + rr) >> 1;
  return sum(v << 1, ll, temp, lb, rb) +
         sum((v << 1) + 1, temp + 1, rr, lb, rb);
}
void addval(int v, int ll, int rr, int pos, int val) {
  if (pos < ll || pos > rr) return;
  if (ll == pos && rr == pos) {
    seg_tree[v] += val;
    return;
  }
  int temp = (ll + rr) >> 1;
  addval(v << 1, ll, temp, pos, val);
  addval((v << 1) + 1, temp + 1, rr, pos, val);
  seg_tree[v] = seg_tree[v << 1] + seg_tree[(v << 1) + 1];
}
void query() {
  int temp;
  cin >> temp;
  switch (temp) {
    case 1: {
      int p;
      cin >> p;
      if (l + 2 * p > r + 1) flipped ^= true, p = r - l - p + 1;
      if (flipped)
        r = r - p;
      else
        l = l + p;
      for (int i = 0; i < (int)(p); ++i) {
        if (flipped) {
          addval(1, 0, n - 1, r - i, paper[r + 1 + i]);
          paper[r - i] += paper[r + 1 + i];
        } else {
          addval(1, 0, n - 1, l + i, paper[l - 1 - i]);
          paper[l + i] += paper[l - 1 - i];
        }
      }
      break;
    }
    case 2: {
      int lb, rb;
      cin >> lb >> rb;
      if (flipped)
        cout << sum(1, 0, n - 1, r - rb + 1, r - lb) << endl;
      else
        cout << sum(1, 0, n - 1, l + lb, l + rb - 1) << endl;
    }
  }
}
int main() {
  cin >> n >> q;
  paper.resize(n);
  seg_tree.resize(4 * n);
  for (int i = 0; i < (int)(n); ++i) paper[i] = 1;
  build(1, 0, n - 1);
  l = 0;
  r = n - 1;
  for (int i = 0; i < (int)(q); ++i) query();
  cin.get();
  cin.get();
  return 0;
}
