#include <iostream>
#include <vector>
#include <string>
#include <functional> // std::hash

using namespace std;

// Hàm băm đơn giản cho số nguyên
size_t hash_int(int val) {
    hash<int> hasher;
    return hasher(val);
}

int main() {
    int n, q;
    cin >> n >> q;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    // Kích thước bảng băm (nên chọn số nguyên tố lớn hơn n để giảm va chạm)
    int hash_table_size = 2 * n + 1;
    vector<vector<int>> hash_table(hash_table_size);

    // Xây dựng bảng băm
    for (int i = 0; i < n; ++i) {
        size_t hash_value = hash_int(a[i]) % hash_table_size;
        hash_table[hash_value].push_back(i + 1); // Lưu trữ chỉ số 1-based
    }

    for (int i = 0; i < q; ++i) {
        string type_str;
        int type_val, y_val;
        cin >> type_str >> type_val >> y_val;

        size_t hash_value = hash_int(y_val) % hash_table_size;
        vector<int>& indices = hash_table[hash_value];

        int first = -1;
        int last = -1;

        for (int index : indices) {
            if (a[index - 1] == y_val) {
                if (first == -1) {
                    first = index;
                }
                last = index;
            }
        }

        if (type_val == 1) {
            cout << first << endl;
        } else if (type_val == 2) {
            cout << last << endl;
        }
    }

    return 0;
}