#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

//RBST 実装

//構造体
struct node_t{
	int val;
	node_t *ch[2];
	int cnt;
	int sum;
	
	node_t(int v): val(v),cnt(1),sum(v) {
		ch[0] = ch[1] = NULL;
	}
};
int count(node_t *t){
	return !t ? 0 : t->cnt;
}
int sum(node_t *t){
	return !t ? mod : t->sum;
}
node_t *update(node_t *t){
	t->cnt = count(t->ch[0])+count(t->ch[1])+1;
	t->sum = min(min(sum(t->ch[0]),sum(t->ch[1])),t->val);
	return t;
}
//乱数
unsigned long xor128() {
  static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}
//merge-split で実装
node_t *merge(node_t *l,node_t *r){
	if(!l || !r) return !l ? r: l;
	
	if(xor128()%(l->cnt+r->cnt) < l->cnt){
		l->ch[1] = merge(l->ch[1],r);
		return update(l);
	}
	else{
		r->ch[0] = merge(l,r->ch[0]);
		return update(r);
	}
}
pair<node_t*,node_t*>split(node_t *t,int k){ //[0,k) [k,n)
	if(!t) return mp((node_t*)NULL,(node_t*)NULL);
	if(k <= count(t->ch[0])){
		pair<node_t*,node_t*>s = split(t->ch[0],k);
		t->ch[0] = s.sc;
		return mp(s.fi,update(t));
	}
	else{
		pair<node_t*,node_t*>s = split(t->ch[1],k-count(t->ch[0])-1);
		t->ch[1] = s.fi;
		return mp(update(t),s.sc);
	}
}
node_t *root = (node_t*)NULL;
node_t *insert(node_t *nd,int k,int val){
	pair<node_t*,node_t*>s = split(nd,k);
	nd = merge(s.fi,new node_t(val));
	nd = merge(nd,s.sc);
	return update(nd);
}
node_t *erase(node_t *nd,int k){
	pair<node_t*,node_t*>s,t;
	t = split(nd,k+1);
	s = split(t.fi,k);
	nd = merge(s.fi,t.sc);
	return update(nd);
}
node_t *shift(node_t *nd,int a,int b){
    pair<node_t*,node_t*>s,t,u;
    s = split(nd,b+1);
    t = split(s.first,b);
    u = split(t.first,a);
    nd = merge(u.first,t.second);
    nd = merge(nd,u.second);
    nd = merge(nd,s.second);
    return nd;
}
int query(node_t* root,int a,int b){
    int sz = count(root);
    if(a>=sz || a>b || b<0) return mod;
    if(a<=0 && sz-1<=b) {return sum(root);}
    a = max(0,a); b = min(b,sz-1);
    int x = count(root->ch[0]);
    int L = query(root->ch[0],a,b);
    int R = query(root->ch[1],a-x-1,b-x-1);
    int ret = min(L,R);
    if(a<=x&&x<=b) ret = min(ret,root->val);
    return ret;
}
void print(node_t* cur,int val){
    cout << cur->val <<" " << val << endl;
    if(cur->ch[0] != (node_t*)NULL) print(cur->ch[0],cur->val);
    if(cur->ch[1] != (node_t*)NULL) print(cur->ch[1],cur->val);
}

int n,q;
int main(){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		int a; scanf("%d",&a); root = insert(root,i,a);
	}
	for(int i=0;i<q;i++){
		int x; scanf("%d",&x);
		if(x == 0){
			int a,b; scanf("%d%d",&a,&b);
			root = shift(root,a,b);
		}
		else if(x == 1){
			int a,b; scanf("%d%d",&a,&b);
			printf("%d\n",query(root,a,b));
		}
		else{
			int a,b; scanf("%d%d",&a,&b);
			root = erase(root,a);
			root = insert(root,a,b);
		}
	}
}


Measured memory_bytes: 15712