#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
inline int lowbit(int x) { return x & -x; }
const int N = 2e5 + 50;
set<unsigned> C[N];
int OP[N], X[N], Y[N], H[N];
void add(unsigned x, unsigned y)
{
    for (; x < N; x += lowbit(x))
        C[x].insert(y);
}
unsigned query(unsigned x, unsigned y)
{
    unsigned ans = -1;
    for (; x; x -= lowbit(x))
    {
        auto ite = C[x].lower_bound(y);
        if (ite != C[x].end())
            ans = min(ans, *ite);
    }
    return ans;
}
int main()
{
    int N, Q;
    char op[3];
    scanf("%d%d", &N, &Q);
    for (int i = 0; i < Q; i++)
    {
        scanf("%s%d%d", op, X + i, Y + i);
        OP[i] = (*op == 'D');
    }
    memcpy(H, X, sizeof(X));
    sort(H, H + Q);
    auto len = unique(H, H + Q) - H;
    for (int i = 0; i < Q; i++) X[i] = lower_bound(H, H + len, X[i]) - H + 1;
    for (int i = 0; i < Q; i++)
    {
        if (OP[i] == 0)
            add(X[i], Y[i]);
        if (OP[i] == 1)
            printf("%d\n", query(X[i], Y[i]));
    }
    return 0;
}
