#include<bits/stdc++.h>
using namespace std;

//#define USING_LONG_LONG
#ifdef USING_LONG_LONG
    #define int long long
    const int INF=1001001001001001001ll;
#else
    const int INF=1001001001;
#endif

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define clr(a) memset((a),0,sizeof(a))
#define CLR(a) memset((a),-1,sizeof(a))
#define each(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define minv(a,b) (a)=min((a),(b))
#define maxv(a,b) (a)=max((a),(b))
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<string>vs;
typedef pair<int,int>pii;
#define fi first
#define se second

const int SQ=400;
struct latte{
    vi v;
    int m;
    latte(){v.clear();m=INF;}
};

int N,Q;
vector<latte>li;
int a[200000];

void build(){
    li.clear();
    latte now;
    rep(i,N){
        now.v.pb(a[i]);
        minv(now.m,a[i]);
        if(i%SQ==SQ-1){li.pb(now);now=latte();}
    }
    if(now.v.size())li.pb(now);
}

signed main(){
    scanf("%d%d",&N,&Q);
    rep(i,N)scanf("%d",&a[i]);

    build();

    rep(qry,Q){
        int type;scanf("%d",&type);
        if(type==0){
            int l,r;scanf("%d%d",&l,&r);
            int cur=0,val;
            rep(i,li.size()){
                if(cur<=r&&r<cur+li[i].v.size()){
                    val=li[i].v[r-cur];
                    for(int j=r-cur+1;j<li[i].v.size();j++){
                        li[i].v[j-1]=li[i].v[j];
                    }
                    li[i].v.pop_back();
                    li[i].m=INF;
                    rep(j,li[i].v.size())minv(li[i].m,li[i].v[j]);
                    break;
                }
                cur+=li[i].v.size();
            }
            cur=0;
            rep(i,li.size()){
                if(cur<=l&&l<cur+li[i].v.size()){
                    li[i].v.pb(0);
                    for(int j=li[i].v.size()-1;j>l-cur;j--){
                        li[i].v[j]=li[i].v[j-1];
                    }
                    li[i].v[l-cur]=val;
                    li[i].m=INF;
                    rep(j,li[i].v.size())minv(li[i].m,li[i].v[j]);
                    break;
                }
                cur+=li[i].v.size();
            }
        }
        else if(type==1){
            int l,r;scanf("%d%d",&l,&r);
            int cur=0;
            int ret=INF;
            rep(i,li.size()){
                if(l<=cur&&cur+li[i].v.size()-1<=r)minv(ret,li[i].m);
                else if(!(r<cur||cur+li[i].v.size()-1<l)){
                    rep(j,li[i].v.size()){
                        if(l<=cur+j&&cur+j<=r)minv(ret,li[i].v[j]);
                    }
                }
                cur+=li[i].v.size();
            }
            printf("%d\n",ret);
        }
        else{
            int pos,val;scanf("%d%d",&pos,&val);
            int cur=0;
            rep(i,li.size()){
                if(cur<=pos&&pos<cur+li[i].v.size()){
                    li[i].v[pos-cur]=val;
                    li[i].m=INF;
                    rep(j,li[i].v.size())minv(li[i].m,li[i].v[j]);
                    break;
                }
                cur+=li[i].v.size();
           }
        }
        if(qry%SQ==SQ-1){
            int cur=0;
            rep(i,li.size()){
                rep(j,li[i].v.size()){
                    a[cur++]=li[i].v[j];
                }
            }
            build();
        }
    }
    return 0;
}

Measured memory_bytes: 3092