#include <iostream>
using namespace std;
//ifstream cin("arbint.in");
//ofstream cout("arbint.out");
int n, q;
int arbore[40000];
void build(int nod, int st, int dr)
{
if (st == dr)
cin >> arbore[nod];
else
{
int mid = (st + dr) / 2;
build(2 * nod, st, mid);
build(2 * nod + 1, mid + 1, dr);
arbore[nod] = max(arbore[2 * nod], arbore[2 * nod + 1]);
}
}
void update(int nod, int st, int dr, int pos, int valoare)
{
if (st == dr)
{
arbore[nod] = valoare;
}
else
{
int mid = (st + dr) / 2;
if (pos <= mid)
{
update(2 * nod, st, mid, pos, valoare);
}
else
{
update(2 * nod + 1, mid + 1, dr, pos, valoare);
}
arbore[nod] = max(arbore[2 * nod], arbore[2 * nod + 1]);
}
}
int sol = -1;
void query(int nod, int st, int dr, int a, int b) {
//cout << st << " " << dr << '\n';
if (a <= st && dr <= b) {
sol = max(sol, arbore[nod]);
}
else {
int mid = (st + dr) / 2;
if (a <= mid)
query(2 * nod, st, mid, a, b);
if (b > mid)
query(2 * nod + 1, mid + 1, dr, a, b);
}
}
int main()
{
cin >> n >> q;
build(1, 1, n);
cout << "\n\n";for (int i = 0; i < 4 * n; i++) cout << arbore[i] << " ";
cout << "\n\n";
for (int i = 0; i < q; i++) {
int caz, x, y;
cin >> caz >> x >> y;
if (caz == 0)
{
sol = -1;
query(1, 1, n, x, y);
cout << sol << '\n';
}
else
{
update(1, 1, n, x, y);
}
}
}