#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
vector<multiset<ll>>tree;
vector<ll>arr;
ll pos,val,del,k,l1,r1;
ll getmax(ll a,ll b){
return a>b?a:b;
}
ll getmin(ll a,ll b){
return a<b?a:b;
}
void implement(int l,int r,int i){
if(l==r){
tree[i].insert(arr[l]);
return;
}
int m=(l+r)/2;
implement(l,m,i*2+1);
implement(m+1,r,i*2+2);
tree[i]=tree[i*2+1];
for(int f=m+1;f<=r;f++)tree[i].insert(arr[f]);
}
void update(int l,int r,int i){
if(l>pos||r<pos)return;
tree[i].erase(arr[pos]);
tree[i].insert(val);
if(l==r){
return;
}
int m=(l+r)/2;
update(l,m,i*2+1);
update(m+1,r,i*2+2);
}
ll solve(int l,int r,int i){
if(l>r1||r<l1)return LLONG_MAX;
if(l>=l1&&r<=r1){
auto it=tree[i].lower_bound(k);
return it==tree[i].end() ? LLONG_MAX:(*it);
}
int m=(l+r)/2;
return getmin(solve(l,m,i*2+1),solve(m+1,r,i*2+2));
}
int main(){
FAST_IO;
ll s;
int n,m,t;
cin>>n>>m;
arr.resize(n);
for(auto &x:arr)cin>>x;
tree.resize(4*n+1);
implement(0,n-1,0);
while(m--){
cin>>t;
if(t==1){
cin>>pos>>val;
pos--;
update(0,n-1,0);
arr[pos]=val;
} else {
cin>>l1>>r1>>k;
l1--;
r1--;
s=solve(0,n-1,0);
if(s==LLONG_MAX)cout<<-1; else
cout<<s;
cout<<endl;
}
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgbGw7CiNkZWZpbmUgRkFTVF9JTyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY2luLnRpZShudWxscHRyKQp2ZWN0b3I8bXVsdGlzZXQ8bGw+PnRyZWU7CnZlY3RvcjxsbD5hcnI7CmxsIHBvcyx2YW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KCmludCBtYWluKCl7CiAgICBGQVNUX0lPOwogICAgbGwgczsKICAgIGludCBuLG0sdDsKICAgIGNpbj4+bj4+bTsKICAgIGFyci5yZXNpemUobik7CiAgICBmb3IoYXV0byAmeDphcnIpY2luPj54OwogICAgdHJlZS5yZXNpemUoNCpuKzEpOwogICAgaW1wbGVtZW50KDAsbi0xLDApOwogICAgd2hpbGUobS0tKXsKICAgICAgICBjaW4+PnQ7CiAgICAgICAgaWYodD09MSl7CiAgICAgICAgICAgIGNpbj4+cG9zPj52YWw7CiAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgICB1cGRhdGUoMCxuLTEsMCk7CiAgICAgICAgICAgIGFycltwb3NdPXZhbDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjaW4+PmwxPj5yMT4+azsKICAgICAgICAgICAgbDEtLTsKICAgICAgICAgICAgcjEtLTsKICAgICAgICAgICAgcz1zb2x2ZSgwLG4tMSwwKTsKICAgICAgICAgICAgaWYocz09TExPTkdfTUFYKWNvdXQ8PC0xOyBlbHNlIAogICAgICAgICAgICBjb3V0PDxzOwogICAgICAgICAgICBjb3V0PDxlbmRsOwogICAgICAgIH0KICAgIH0KfQ==