#include <bits/stdc++.h>
using namespace std;
template <typename T>
class binary_indexed_tree {
  vector<T> _t;
  T sum(int r) {
    T result = 0;
    while (r > 0) {
      result += _t[r];
      r = (r & (r + 1)) - 1;
    }
    return result;
  }

 public:
  binary_indexed_tree(const size_t n) { _t.assign(n + 1, 0); }
  binary_indexed_tree(const vector<T> &data)
      : binary_indexed_tree(data.size()) {
    for (int i = 0; i < data.size(); i++) inc(i, data[i]);
  }
  T sum(const int l, const int r) { return sum(r + 1) - sum(l); }
  void inc(int index, const T delta) {
    index++;
    while (index < _t.size()) {
      _t[index] += delta;
      index = index | (index + 1);
    }
  }
};
class problem {
  int n;
  int q;
  binary_indexed_tree<int64_t> *bit;
  vector<int64_t> a;

 public:
  problem() { ios_base::sync_with_stdio(false); }
  void solve() {
    int n, q;
    cin >> n >> q;
    a.assign(n, 1);
    bit = new binary_indexed_tree<int64_t>(a);
    bool flipped = false;
    int left = 0;
    int right = n;
    for (int k = (0); k <= (int)((q)-1); ++k) {
      int t;
      cin >> t;
      if (t == 1) {
        int p;
        cin >> p;
        if (!flipped) {
          if (2 * p > right - left) {
            for (int i = (0); i <= (int)((right - left - p) - 1); ++i) {
              a[left + p - i - 1] += a[left + p + i];
              bit->inc(left + p - i - 1, a[left + p + i]);
            }
            flipped = true;
            right = left + p;
          } else {
            for (int i = (0); i <= (int)((p)-1); ++i) {
              a[left + p + i] += a[left + p - i - 1];
              bit->inc(left + p + i, a[left + p - i - 1]);
            }
            left = left + p;
          }
        } else {
          if (2 * p > right - left) {
            for (int i = (0); i <= (int)((right - left - p) - 1); ++i) {
              a[right - p + i] += a[right - p - i - 1];
              bit->inc(right - p + i, a[right - p - i - 1]);
            }
            flipped = false;
            left = right - p;
          } else {
            for (int i = (0); i <= (int)((p)-1); ++i) {
              a[right - p - i - 1] += a[right - p + i];
              bit->inc(right - p - i - 1, a[right - p + i]);
            }
            right = right - p;
          }
        }
      } else if (t == 2) {
        int l, r;
        cin >> l >> r;
        if (flipped)
          cout << bit->sum(right - r, right - l - 1) << endl;
        else
          cout << bit->sum(left + l, left + r - 1) << endl;
      }
    }
  }
};
int main() {
  problem *p = new problem();
  p->solve();
  return 0;
}
