#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int nmax = 100005;
int aint[4 * nmax], a[nmax], ans;
int n, m;
void Build(int nod, int st, int dr)
{
if(st == dr)
{
aint[nod] = a[st];
return;
}
int mid = (st + dr) / 2;
Build(2 * nod, st, mid);
Build(2 * nod + 1, mid + 1, dr);
aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
}
void Update(int nod, int st, int dr, int poz, int val)
{
if(st == dr)
{
aint[nod] = val;
return;
}
int mid = (st + dr) / 2;
if(poz <= mid)
Update(2 * nod, st, mid, poz, val);
else
Update(2 * nod + 1, mid + 1, dr, poz, val);
aint[nod] = max(aint[2 * nod], aint[2 * nod + 1]);
}
void Query(int nod, int st, int dr, int lquery, int rquery)
{
if(lquery <= st && rquery >= dr)
{
ans = max(ans, aint[nod]);
return;
}
int mid = (st + dr) / 2;
if(lquery <= mid)
Query(2 * nod, st, mid, lquery, rquery);
if(rquery > mid)
Query(2 * nod + 1, mid + 1, dr, lquery, rquery);
}
void Citire()
{
int i, op, x, y;
fin >> n >> m;
for(i = 1;i <= n;i++)
fin >> a[i];
Build(1, 1, n);
for(i = 1;i <= m;i++)
{
fin >> op >> x >> y;
if(op == 1)
Update(1, 1, n, x, y);
else
{
ans = -1;
Query(1, 1, n, x, y);
fout << ans << "\n";
}
}
}
int main()
{
Citire();
return 0;
}