#include <iostream>
#include <fstream>
using namespace std;
int A[100014*4+1],n,m,sol;
void update (int st, int dr, int nod,int poz,int val)
{
if (st==dr)
A[nod]=val;
else
{
int mij=(st+dr)/2;
if (poz<=mij)
update(st,mij,nod*2,poz,val);
else
update(mij+1,dr,nod*2+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]);
else
{
int mij=(st+dr)/2;
if (a<=mij)
query(st,mij,nod*2,a,b);
if (b>=mij+1)
query(mij+1,dr,nod*2+1,a,b);
}
}
int main()
{
int i,var,x,poz,a,b ;
fstream f,g;
f.open("arbint.in",ios::in);
g.open("arbint.out",ios::out);
f>>n>>m;
for (i=1;i<=n;i++)
{
f>>x;
poz=i;
update(1,n,1,i,x);
}
for (i=1;i<=m;i++)
{
f>>var>>a>>b;
if (var==0)
{
sol=-1;
query(1,n,1,a,b);
g<<sol<<'\n';
}
else
update(1,n,1,a,b);
}
}