#include <bits/stdc++.h>
// #ifndef ONLINE_JUDGE
// #include "template.cpp"
// #else
// #define debug(...)
// #define debugArr(...)
// #endif
#define F first
#define S second
#define int long long
#define double long double
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define mp(x, y) make_pair(x, y)
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define INF (int)1e18
using namespace std;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pbb = pair<bool, bool>;
using pcc = pair<char, char>;
using pss = pair<string, string>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpdd = vector<pair<double, double>>;
using vpbb = vector<pair<bool, bool>>;
using vpcc = vector<pair<char, char>>;
using vpss = vector<pair<string, string>>;
using vvi = vector<vector<int>>;
using vvd = vector<vector<double>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvpii = vector<vector<pair<int, int>>>;
using vvpdd = vector<vector<pair<double, double>>>;
using vvpbb = vector<vector<pair<bool, bool>>>;
using vvpcc = vector<vector<pair<char, char>>>;
using vvpss = vector<vector<pair<string, string>>>;
// clang-format off
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> T sqrt_(T elem) {int l=1,r=elem;while(l<=r){int mid=l+(r-l)/2LL;if(mid>elem/mid){r=mid-1;}else{int val=mid*mid;if(val<=elem){l=mid+1;}else{r=mid-1;}}}return r;}
template <class T> T ceil_(T a,T b) {return(a+b-1)/b;};
template <class T> T mod_add(T a,T b,T mod){return((a%mod)+(b%mod))% mod;}
template <class T> T mod_sub(T a,T b,T mod){return((a%mod)-(b%mod)+mod)%mod;}
template <class T> T mod_mul(T a,T b,T mod){return((a%mod)*(b%mod))%mod;}
template <class T> T mod_inv(T a,T mod){T m0=mod,y=0,x=1;if(mod==1)return 0;while(a>1){T q=a/mod;T t=mod;mod=a%mod,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}
template <class T> T mod_div(T a,T b,T mod){return mod_mul(a,mod_inv(b,mod),mod);}
// clang-format on
const int m = 10000000;
void solve() {
int n, k;
cin >> n >> k;
vi a(n + 1);
vector<tuple<int, int, int>> b(k);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (auto &[x, y, z] : b) {
cin >> x >> y >> z;
}
vpii child(m), dp(m);
vi par(m), initId(n + 1);
queue<tuple<int, int, int>> q;
int cnt = 1;
q.push({1, n, 1});
par[1] = -1;
while (!q.empty()) {
auto [l, r, id] = q.front();
q.pop();
if (r - l <= 0) {
initId[l] = id;
continue;
}
int l1 = l, r1 = l + (((r - l + 1) / 2) - 1);
int l2 = r1 + 1, r2 = r;
child[id] = {cnt + 1, cnt + 2};
par[cnt + 1] = par[cnt + 2] = id;
q.push({l1, r1, cnt + 1});
q.push({l2, r2, cnt + 2});
cnt += 2;
}
queue<int> q2;
for (int i = 0; i < m; i++) {
dp[i] = {-INF, INF};
}
for (int i = 1; i <= n; i++) {
dp[initId[i]] = {a[i], a[i]};
q2.push(initId[i]);
}
while (!q2.empty()) {
int id = q2.front();
q2.pop();
if (id == 1) {
continue;
}
dp[par[id]].F = max(dp[par[id]].F, dp[id].S);
dp[par[id]].S = min(dp[par[id]].S, dp[id].F);
q2.push(par[id]);
}
for (const auto [ind, v, p] : b) {
a[ind] = v;
for (int i = 0; i < m; i++) {
dp[i] = {-INF, INF};
}
for (int i = 1; i <= n; i++) {
dp[initId[i]] = {a[i], a[i]};
q2.push(initId[i]);
}
while (!q2.empty()) {
int id = q2.front();
q2.pop();
if (id == 1) {
continue;
}
dp[par[id]].F = max(dp[par[id]].F, dp[id].S);
dp[par[id]].S = min(dp[par[id]].S, dp[id].F);
q2.push(par[id]);
}
if (p == 0) {
cout << dp[1].S << '\n';
} else {
cout << dp[1].F << '\n';
}
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tt = 1, count = 1;
// cin >> tt;
while (tt--) {
// cout << "Case #" << count << ": ";
solve();
++count;
}
return 0;
}