#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = INT_MAX;
const int NINF = INT_MIN;
const int MAXLOG = 21;
const int MAXSEG = (1 << 18);
const int MUL = 1000001;
const int MOD = 1000000007;
void setIO(string name) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (name == "input") {
    freopen("input.txt", "r", stdin);
  } else if (name == "stdio") {
  } else {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
struct sum_seg_tree {
  int n;
  int segTree[MAXSEG];
  sum_seg_tree() {
    this->n = 0;
    fill(segTree, segTree + MAXSEG, 0);
  }
  sum_seg_tree(int n) {
    this->n = n;
    fill(segTree, segTree + MAXSEG, 0);
  }
  int query(int i, int j) { return queryUtil(0, 0, n - 1, i, j); }
  int queryUtil(int node, int a, int b, int i, int j) {
    if (a >= i && b <= j) {
      return segTree[node];
    }
    if (a > j || b < i) {
      return 0;
    }
    int mid = (a + b) / 2;
    int l = queryUtil(2 * node + 1, a, mid, i, j);
    int r = queryUtil(2 * node + 2, mid + 1, b, i, j);
    return l + r;
  }
  void update(int i, int val) { updateUtil(0, 0, n - 1, i, val); }
  void updateUtil(int node, int a, int b, int i, int val) {
    if (i < a || i > b) {
      return;
    }
    if (a == b) {
      segTree[node] += val;
    } else if (a != b) {
      int mid = (a + b) / 2;
      updateUtil(2 * node + 1, a, mid, i, val);
      updateUtil(2 * node + 2, mid + 1, b, i, val);
      segTree[node] = segTree[2 * node + 1] + segTree[2 * node + 2];
    }
  }
};
int n, q;
int main() {
  setIO("stdio");
  cin >> n >> q;
  sum_seg_tree segTree(n);
  for (int i = (0); i < (n); ++i) {
    segTree.update(i, 1);
  }
  int type;
  int start = 0, length = n, flipped = 0;
  for (int query = (0); query < (q); ++query) {
    cin >> type;
    if (type == 1) {
      int a;
      cin >> a;
      if (!flipped) {
        if (a > length / 2) {
          flipped ^= 1;
          for (int i = (a); i < (length); ++i) {
            int v = segTree.query(i + start, i + start);
            segTree.update(2 * a - i - 1 + start, v);
          }
          length = a;
        } else {
          for (int i = (a - 1); i >= (0); --i) {
            int v = segTree.query(i + start, i + start);
            segTree.update(2 * a - i - 1 + start, v);
          }
          start = start + a;
          length = length - a;
        }
      } else if (flipped) {
        a = length - a;
        if (a <= length / 2) {
          flipped ^= 1;
          for (int i = (a - 1); i >= (0); --i) {
            int v = segTree.query(i + start, i + start);
            segTree.update(2 * a - i - 1 + start, v);
          }
          start = start + a;
          length = length - a;
        } else {
          for (int i = (a); i < (length); ++i) {
            int v = segTree.query(i + start, i + start);
            segTree.update(2 * a - i - 1 + start, v);
          }
          length = a;
        }
      }
    } else if (type == 2) {
      int a, b;
      cin >> a >> b;
      if (!flipped) {
        cout << segTree.query(a + start, b - 1 + start) << '\n';
      } else {
        a = length - a;
        b = length - b;
        cout << segTree.query(b + start, a + start - 1) << '\n';
      }
    }
  }
}
