#include <fstream>
#pragma GCC optimize ("Ofast")
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
int n, m, aint[500020], maxim, op, x, y;
int left_son(int nod)
{
return 2*nod;
}
int right_son(int nod)
{
return 2*nod+1;
}
void update(int nod, int st, int dr, int poz, int val)
{
if(st==dr)
{
aint[nod]=val;
return;
}
int mij = (st+dr)/2;
if(poz<=mij)
update(left_son(nod), st, mij, poz, val);
else
update(right_son(nod), mij+1, dr, poz, val);
aint[nod]=max(aint[left_son(nod)], aint[right_son(nod)]);
}
void query (int nod, int st, int dr, int query_st, int query_dr)
{
if(query_st <= st && dr <= query_dr)
{
maxim = max(maxim, aint[nod]);
return;
}
int mij = (st+dr)/2;
if(query_st <= mij)
query(left_son(nod), st, mij, query_st, query_dr);
if(mij+1 <= query_dr)
query(right_son(nod), mij+1, dr, query_st, query_dr);
}
int main()
{
fin>>n>>m;
for(int i=1; i<=n; i++)
{
int x;
fin>>x;
update(1, 1, n, i, x);
}
while(m--)
{
fin>>op>>x>>y;
maxim = -1;
if(op==0)
{
query(1, 1, n, x, y);
fout<<maxim<<'\n';
}
if(op==1)
update(1, 1, n, x, y);
}
return 0;
}