#include <iostream>
#include <fstream>
using namespace std;
int n, m, i, j, k, cod, l, Max[1000005], x, y, maxi;
void update(int pos, int nod, int st, int dr) {
if (st == dr) {
Max[nod] = x;
return;
}
int mid = (st + dr) / 2;
if (pos <= mid) update(pos, 2 * nod, st, mid);
else if (pos > mid) update(pos, 2 * nod + 1, mid + 1, dr);
Max[nod] = max(Max[nod * 2], Max[nod * 2 + 1]);
}
void querry(int nod, int st, int dr, int ajungst, int ajungdr) {
if (st >= ajungst and dr <= ajungdr) {
if (Max[nod] > maxi) maxi = Max[nod];
return;
}
int mid = (st + dr) / 2;
if (ajungst <= mid) querry(nod * 2, st, mid, ajungst, ajungdr);
if (ajungdr > mid) querry(nod * 2 + 1, mid + 1, dr, ajungst, ajungdr);
}
int main()
{
ifstream cin("arbint.in");
ofstream cout("arbint.out");
cin >> n >> m;
for (i = 1;i <= n;i++) {
cin >> x;
update(i, 1, 1, n);
}
for (i = 1;i <= m;i++) {
cin >> cod >> x >> y;
if (cod == 0)
{
maxi = -1;
querry(1, 1, n, x, y);
cout << maxi << '\n';
}
else {
swap(x, y);
update(y, 1, 1, n);
}
}
}