#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100005;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int aint[4 * NMAX];
int a[NMAX];
int n, m;
int maxim = -1;
int Leftson(int node)
{
return 2 * node;
}
int Rightson(int node)
{
return 2 * node + 1;
}
void Build(int node, int left, int right, int poz)
{
if(left == right)
{
aint[node] = a[poz];
return;
}
int mid = (left + right) / 2;
if(mid >= poz)
Build(Leftson(node), left, mid, poz);
else
Build(Rightson(node), mid + 1, right, poz);
aint[node] = max(aint[Leftson(node)], aint[Rightson(node)]);
}
void Update(int node, int left, int right, int poz, int val)
{
if(left == right)
{
aint[node] = val;
a[poz] = val;
return;
}
int mid = (left + right) / 2;
if(mid >= poz)
Update(Leftson(node), left, mid, poz, val);
else
Update(Rightson(node), mid + 1, right, poz, val);
aint[node] = max(aint[Leftson(node)], aint[Rightson(node)]);
}
void Query(int node, int left, int right, int a, int b)
{
///cout << left << " " << right << " " << node << "\n";
if(a <= left && right <= b)
{
maxim = max(maxim, aint[node]);
return;
}
int mid = (left + right) / 2;
if(a <= mid)
Query(Leftson(node), left, mid, a, b);
if(b > mid)
Query(Rightson(node), mid + 1, right, a, b);
}
int main()
{
int i;
fin >> n >> m;
for(i = 1;i <= n;i++)
fin >> a[i];
for(i = 1;i <= n;i++)
Build(1, 1, n, i);
for(i = 1;i <= m;i++)
{
int op, x, y;
fin >> op >> x >> y;
if(op == 0)
{
maxim = -1;
Query(1, 1, n, x, y);
fout << maxim << "\n";
}
else
{
Update(1, 1, n, x, y);
}
}
return 0;
}