#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn = 1 << 17;

int n, m, cnt;
int o[maxn];
int l[maxn], r[maxn], x[maxn], deleted[maxn];
vector<int> st[2 * maxn];

void add(int v, int tl, int tr, int l, int r, int x) {
	if (l > r) return;
	if (tl == l && tr == r) {
		st[v].push_back(x);
		return;
	}
	int tm = (tl + tr) >> 1;
	add(v * 2, tl, tm, l, min(r, tm), x);
	add(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
}

int get(int v, int tl, int tr, int x) {
	int o = -1;
	while (!st[v].empty() && deleted[st[v].back()]) st[v].pop_back();
	if (!st[v].empty()) {
		o = st[v].back();
	}
	if (tl == tr) {
		return o;
	}
	int tm = (tl + tr) >> 1;
	if (x <= tm) return max(o, get(v * 2, tl, tm, x));
	return max(o, get(v * 2 + 1, tm + 1, tr, x));
}

int main() {
	freopen("stacks.in", "r", stdin);
	freopen("stacks.out", "w", stdout);

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		char c;
		cin >> c;
		if (c == 'A') {
			cin >> l[i] >> r[i] >> x[i];
			o[++cnt] = i;
			add(1, 0, n - 1, l[i] - 1, r[i] - 1, i);
		}
		if (c == 'G') {
			int id;
			cin >> id;
			int ans = get(1, 0, n - 1, id - 1);
			if (ans != -1) ans = x[ans];
			cout << ans << endl;
		}
		if (c == 'R') {
			int id;
			cin >> id;
			deleted[o[id]] = 1;
		}
	}

	return 0;
}