//splay 0.54 sec
/*
SplayTree

??????????????????????????????
Node?????????+?????????????????????
update
?????¨????????¨???
*/
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;

template<class D>
struct SplayTree{
	struct Node;
	using NP = Node*;
	static NP nil;

	struct Node{
		NP p,l,r;
		int sz;
		D v,sm;
		Node(D v) :p(nullptr),l(nil),r(nil),sz(1),v(v),sm(v){}
		Node() : p(nullptr),l(nullptr),r(nullptr),sz(0),v(D::e()),sm(D::e()){}
		int pos(){			//??????????????????,????????????,????????¨??????(or nil)???
			if(p&&p->l == this) return -1;
			if(p&&p->r == this) return 1;
			return 0;
		}
		void rot(){				//root??§?????¶??¨???
			NP pp=p->p;
			int pps=p->pos();
			if(p->l==this){
				p->l=r,r->p=p,r=p,p->p=this;
			}else{
				p->r=l,l->p=p,l=p,p->p=this;
			}
			p->update();
//			update();
			p=pp;
			if(pps==0) return;
			if(pps==-1) pp->l=this;
			else pp->r=this;
//			pp->update();	//?????????????
		}
		void splay(){			//this???root????????£?????????
			while(true){
				int ps=pos();
				if(ps==0) break;
				int pps=p->pos();
				if(pps==0){		//zig
					rot();
				}else if(ps==pps){		//zigzig
					p->rot();rot();
				}else{					//zigzag
					rot();rot();
				}
			}
		}
		NP splay(int k){			//????????????????????????kth(0-indexed)???root????????£????????????????????????????????????
			assert(0<=k&&k<sz);
			if(k<l->sz){
				return l->splay(k);
			}else if(k==l->sz){
				splay();
				return this;
			}else{
				return r->splay(k-(l->sz+1));
			}
		}
		NP update(){		//?????±??´??°(????????£?????????????????°????????¨??????) (?????????update??????return?????????????\?????????§NP?????????)
			sz=1+l->sz+r->sz;
			sm = v;
			if(l->sz) sm = l->sm + sm;	//if(l) ?????¨nil??§????????¶?????????????????????
			if(r->sz) sm = sm + r->sm;
			return this;
		}

		void showtree(){
			cout<<"[";
			if(l->sz) l->showtree();
			cout<<v;
			if(r->sz) r->showtree();
			cout<<"]";
		}

	};
	NP n;

	/*
		(r!=nil??????)r????????????????????????
		r???????????????l
	*/
	static NP merge(NP l,NP r){
		if(r==nil) return l;
		r=r->splay(0);
		r->l=l;
		l->p=r;
		return r->update();
	}
	/*
		kth??§split(k=0??????fs=null)
		??¨????????????k??????????????£????????????pair(????????????,????????\???)?????????.?????????????????£???????????????(????????\???)??????,??¨?????????k
		?????¬??????split????¬¬????????°???root????????§??????????????°????????????????????????????
		??¨?????????split????????? ([1,2,3,4] -> [1,2][3,4] -> [1][2][3,4]) ??¶???????????????root?????????
	*/
	static pair<NP,NP> split(NP x,int k){
		assert(0<=k&&k<=x->sz);
		if(k==x->sz) return {x,nil};
		x=x->splay(k);
		NP l=x->l;
		l->p = nullptr;
		x->l = nil;
		return {l,x->update()};
	}
	static NP build(int sz,D vs[]){				//init
		if(!sz) return nil;
		int md=sz/2;
		NP x= new Node(vs[md]);
		x->l = build(md,vs);
		x->l->p=x;
		x->r=build(sz-(md+1),vs+md+1);
		x->r->p=x;
		return x->update();
	}
	static NP build(const vector<D>& vs){
		return build(vs.size(),vs,0);
	}
	static NP build(int sz,const vector<D>& vs,int off){				//init
		if(!sz) return nil;
		int md=sz/2;
		NP x= new Node(vs[off+md]);
		x->l = build(md,vs,off);
		x->l->p=x;
		x->r=build(sz-(md+1),vs,off+md+1);
		x->r->p=x;
		return x->update();
	}

	SplayTree() : n(nil){}
	SplayTree(NP n) : n(n){}
	SplayTree(int sz,D vs[]){
		n=build(sz,vs);
	}
	SplayTree(vector<D> vs){
		n=build(vs);
	}

	void insert(int k,D v){
		auto u=split(n,k);
		n=merge(merge(u.fs,new Node(v)),u.sc);
	}
	void erase(int k){
		auto u=split(n,k);
		n=merge(u.fs,split(u.sc,1).sc);
	}
	void merge(SplayTree t){
		n=merge(n,t.n);
	}
	int sz(){
		return n->sz;
	}
	D get(int k){			//kth info
		auto a=split(n,k);
		auto b=split(a.sc,1);
		D ret=b.fs->v;
		n=merge(merge(a.fs,b.fs),b.sc);
		return ret;
	}
	void assign(int k,D d){
		auto a = split(n,k);
		auto b = split(a.sc,1);
		n = merge(merge(a.fs,new Node(d)),b.sc);
	}
	D query(int l,int r){			//[l,r)
		auto b=split(n,r);
		auto a=split(b.fs,l);
		D ret=a.sc->sm;
		n=merge(merge(a.fs,a.sc),b.sc);
		return ret;
	}

	/*
		search
		??????????????¨??¨??????????????????????????????
		????????????????????£??????????????????????????§????????¨???????????£??¨?????°?????¬????????????
		?????£??????????????????????????????????????¨????????????????????¨????????¨??¨???????????????
		D ??? operator< ??¨ operator<= ?????????
	*/
	int lower_bound(D x){		//x??\?????§???????°?????????¨??????id?????????
		NP p=n;
		int ret=0;
		while(p!=nil){
			if(x<=p->v) p=p->l;
			else ret+=(p->l->sz)+1,p=p->r;
		}
		return ret;
	}
	int upper_bound(D x){		//x????????§??§???????°?????????¨??????id?????????
		NP p=n;
		int ret=0;
		while(p!=nil){
			if(x<p->v) p=p->l;
			else ret+=(p->l->sz)+1,p=p->r;
		}
		return ret;
	}

	/*
		debug
	*/
	void showtree(){
		n->showtree();
		cout<<endl;
	}
};


struct Dmin{		//(int,min,inf)
	int x;
	Dmin(){}
	Dmin(int x):x(x){}
	static Dmin e(){
		return Dmin(1e9);
	}
	Dmin operator+(const Dmin& r) const {
		return Dmin(min(x,r.x));
	}
	friend ostream& operator<<(ostream& o,const Dmin& d){return o<<d.x;}
};

using D = Dmin;
template<>
SplayTree<Dmin>::NP SplayTree<Dmin>::nil = new SplayTree<Dmin>::Node();

SplayTree<D>::NP merge(SplayTree<D>::NP x,SplayTree<D>::NP y){
	return SplayTree<D>::merge(x,y);
}
pair<SplayTree<D>::NP,SplayTree<D>::NP> split(SplayTree<D>::NP x,int k){
	return SplayTree<D>::split(x,k);
}

int main(){
	int N,Q;
	vector<D> vs;
	cin>>N>>Q;
	rep(i,N){
		int x;
		cin>>x;
		vs.pb(D(x));
	}
	SplayTree<D> st(vs);
	rep(qt,Q){
		int x,y,z;
		cin>>x>>y>>z;
		if(x==0){	//[y..z-1][z] -> [z][y..z-1]
			auto a = split(st.n,y);	//[0..y-1][y..N-1]
			auto b = split(a.sc,z-y+1);	//[y..z][~]
			auto c = split(b.fs,z-y);		//[y..z-1][z]
			st.n = merge(merge(a.fs,c.sc),merge(c.fs,b.sc));
		}
		if(x==1){
			cout<<st.query(y,z+1).x<<endl;
		}
		if(x==2){
			st.assign(y,z);
		}
//		st.showtree();
	}
}

Measured memory_bytes: 16028