/*
Bogdanescu Ionut
grupa 134
Arbori de intervale
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
class AI{
int N,LM;
int *pinit,*arb;
public:
AI(int lu);
~AI();
void cstr(int st,int dr,int poz);
int size();
void update(int val,int poz);
int query(int st,int dr,int x,int y,int poz);
void scrie();
};
AI::AI(int lu){
N=lu;
LM=0;
pinit=new int[lu];
arb=new int[4*lu+100];
this->cstr(1,lu,1);
}
AI::~AI(){
N=0;
delete[] pinit;
delete[] arb;
}
void AI::cstr(int st,int dr,int poz){
if(st==dr){
pinit[st]=poz;
if(poz>LM)
LM=poz;
return;
}
int mij=(st+dr)>>1;
this->cstr(st,mij,poz*2);
this->cstr(mij+1,dr,poz*2+1);
}
int AI::size(){
return N;
}
void AI::update(int val,int poz){
poz=pinit[poz];
arb[poz]=val;
poz>>=1;
while(poz){
arb[poz]=max(arb[poz*2],arb[poz*2+1]);
poz>>=1;
}
}
void AI::scrie(){
for(int i=1;i<=LM;++i){
cout<<arb[i]<<endl;
}
}
int AI::query(int st,int dr,int x,int y,int poz){
if(x<=st && dr<=y)
return arb[poz];
if(dr<x || y<st)
return -1;
int mij=(st+dr)>>1,a,b;
a=this->query(st,mij,x,y,poz*2);
b=this->query(mij+1,dr,x,y,poz*2+1);
return a>b?a:b;
}
int main(){
int n,m,x,y;
f>>n>>m;
AI nr(n);
for(int i=1;i<=nr.size();++i){
f>>n;
nr.update(n,i);
}
//nr.scrie();
for(int i=0;i<m;++i){
f>>n>>x>>y;
if(!n)
g<<nr.query(1,nr.size(),x,y,1)<<'\n';
else
nr.update(y,x);
}
f.close();
return 0;
}