#include<fstream>
using namespace std;
int n, m, i, x[100002], A[200002], sol, op, a, b;
void build(int st, int dr, int nod)
{
if(st==dr)
{
A[nod]=x[st];
return ;
}
int mij=st+(dr-st)/2;
build(st, mij, 2*nod);
build(mij+1, dr, 2*nod+1);
A[nod]=max(A[2*nod], A[2*nod+1]);
}
void update(int st, int dr, int nod, int poz, int val)
{
if(st==dr)
{
A[nod]=val;
return ;
}
int mij=st+(dr-st)/2;
if(poz<=mij)
update(st, mij, 2*nod, poz, val);
if(poz>=mij+1)
update(mij+1, dr, 2*nod+1, poz, val);
A[nod]=max(A[2*nod], A[2*nod+1]);
}
void query(int st, int dr, int nod, int a, int b)
{
if(a<=st && dr<=b)
{
sol=max(sol, A[nod]);
return ;
}
int mij=st+(dr-st)/2;
if(a<=mij)
query(st, mij, 2*nod, a, b);
if(b>=mij+1)
query(mij+1, dr, 2*nod+1, a, b);
}
ifstream in("arbint.in");
ofstream out("arbint.out");
int main()
{
in>>n>>m;
for(i=1; i<=n; i++)
in>>x[i];
build(1, n, 1);
for(;m--;)
{
in>>op>>a>>b;
if(op==0)
{
sol=-1;
query(1, n, 1, a, b);
out<<sol<<"\n";
}else
{
update(1, n, 1, a, b);
}
}
return 0;
}