#include <bits/stdc++.h>
using namespace std;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
  typename T::value_type sum = 0;
  for (int i = 0; i < n; ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
vector<int> t;
void build(vector<int>& a, int v, int tl, int tr) {
  if (tl == tr)
    t[v] = a[tl];
  else {
    int tm = (tl + tr) / 2;
    build(a, v * 2 + 1, tl, tm);
    build(a, v * 2 + 2, tm + 1, tr);
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
  }
}
int sum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return t[v];
  int tm = (tl + tr) / 2;
  return sum(v * 2 + 1, tl, tm, l, min(r, tm)) +
         sum(v * 2 + 2, tm + 1, tr, max(l, tm + 1), r);
}
void update(int v, int tl, int tr, int pos, int new_val) {
  if (tl == tr) {
    t[v] = new_val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(v * 2 + 1, tl, tm, pos, new_val);
    else
      update(v * 2 + 2, tm + 1, tr, pos, new_val);
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
  }
}
void add(int v, int tl, int tr, int pos, int new_val) {
  if (tl == tr) {
    t[v] += new_val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      add(v * 2 + 1, tl, tm, pos, new_val);
    else
      add(v * 2 + 2, tm + 1, tr, pos, new_val);
    t[v] = t[v * 2 + 1] + t[v * 2 + 2];
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  t.resize(4 * n);
  vector<int> v(n, 1);
  int flag = 0;
  build(v, 0, 0, n - 1);
  int l = 0, r = v.size();
  for (int k = 0; k < q; ++k) {
    int tmp;
    cin >> tmp;
    if (tmp == 1) {
      int x;
      cin >> x;
      if ((x <= (r - l) / 2) ^ flag) {
        if (flag) {
          x = r - l - x;
        }
        for (int i = l + x, j = l + x - 1; j >= l; ++i, --j) {
          add(0, 0, n - 1, i, sum(0, 0, n - 1, j, j));
        }
        l += x;
        flag = 0;
      } else {
        if (flag) {
          x = r - l - x;
        }
        for (int i = l + x, j = l + x - 1; i < r; ++i, --j) {
          add(0, 0, n - 1, j, sum(0, 0, n - 1, i, i));
        }
        r = l + x;
        flag = 1;
      }
    } else {
      int tl, tr;
      cin >> tl >> tr;
      if (!flag) {
        cout << sum(0, 0, n - 1, l + tl, l + tr - 1) << "\n";
      } else {
        cout << sum(0, 0, n - 1, r - tr, r - tl - 1) << "\n";
      }
    }
  }
  return 0;
}
