#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, qc;
  cin >> n >> qc;

  vector<int> arr (n + 1);
  iota(arr.begin(), arr.end(), 0);

  for (int i = 0; i < qc; i++) {
    int type;
    cin >> type;

    if (type == 1) {
      int l, r;
      cin >> l >> r;

      reverse(arr.begin() + l, arr.begin() + r + 1);
    } else if (type == 2) {
      int x;
      cin >> x;

      cout << arr[x] << '\n';
    } else {
      int y;
      cin >> y;

      cout << 1 << '\n';
    }
  }
}
