#include <iostream>
#include <stdio.h>
using namespace std;
const int NMAX = (1 << 13), LOGNMAX = 14;
int segTree[NMAX * LOGNMAX - 1];
int v[NMAX];
int pos, val;
int lSon(int node);
int rSon(int node);
void initTree(int node, int lo, int hi);
void update(int node, int lo, int hi);
int query(int node, int lo, int hi, int qlo, int qhi);
int queryNaive(int lo, int hi);
int queryNaive(int lo, int hi)
{
int minInd = lo, i;
for (i = lo; i <= hi; i++)
if (v[i] > v[minInd])
minInd = i;
return minInd;
}
int main()
{
int i, n, c, lo, hi, nrc;
FILE *fin = fopen("arbint.in", "r");
fscanf(fin, "%d%d", &n, &nrc);
for (i = 0; i < n; i++)
fscanf(fin, "%d", &v[i]);
FILE *fout = fopen("arbint.out", "w");
initTree(1, 0, n - 1);
for (i = 0; i < nrc; i++)
{
fscanf(fin, "%d", &c);
if (c == 0)
{
fscanf(fin, "%d%d", &lo, &hi);
fprintf(fout, "%d\n", v[query(1, 0, n - 1, lo - 1, hi - 1)]);
}
else
{
fscanf(fin, "%d%d", &pos, &val);
pos--;
v[pos] = val;
update(1, 0, n - 1);
}
}
fclose(fin);
fclose(fout);
return 0;
}
inline int lSon(int node) {return (node << 1);}
inline int rSon(int node) {return (node << 1) + 1;}
void initTree(int node, int lo, int hi)
{
if (lo == hi)
segTree[node] = lo;
else
{
int mid = (lo + hi) >> 1;
initTree(lSon(node), lo, mid);
initTree(rSon(node), mid + 1, hi);
if (v[segTree[rSon(node)]] > v[segTree[lSon(node)]])
segTree[node] = segTree[rSon(node)];
else
segTree[node] = segTree[lSon(node)];
}
}
void update(int node, int lo, int hi)
{
if (lo == hi)
return;
int mid = (lo + hi) >> 1;
if (pos <= mid)
update(lSon(node), lo, mid);
else
update(rSon(node), mid + 1, hi);
if (v[segTree[lSon(node)]] > v[segTree[rSon(node)]])
segTree[node] = segTree[lSon(node)];
else
segTree[node] = segTree[rSon(node)];
}
int query(int node, int lo, int hi, int qlo, int qhi)
{
if (qlo > hi || qhi < lo)
return -1;
if (qlo <= lo && qhi >= hi)
return segTree[node];
int mid = ((lo + hi) >> 1);
int ind1 = query(lSon(node), lo, mid, qlo, qhi);
int ind2 = query(rSon(node), mid + 1, hi, qlo, qhi);
if (ind1 == -1)
return ind2;
if (ind2 == -1)
return ind1;
if (v[ind1] > v[ind2])
return ind1;
return ind2;
}