#include<iostream>
#include<algorithm>
#include<map>

using namespace std;
#define INF (1 << 30)
#define size(x) (x?x->size:0)
#define nmin(x) (x?x->min:INF)

struct Node{
	int val, min, size;
	Node *l, *r;        
	Node(int x){
		val = x;
		min = x;
		size = 1;
		l = r = 0;	
	}	
};

Node *root = 0;
                    
typedef pair<Node*, Node*> P;
int vals[108000];
int p = 0;
void dfs(Node *a){
	if(a->l)dfs(a->l);
	vals[p++] = a->val;
	if(a->r)dfs(a->r);
}

void view(Node *a){
	p = 0;
	int s = size(a);
	dfs(a);
	for(int i = 0;i < p;i++){
		cout << vals[i] << " ";
	}cout << endl;
}

Node *update(Node *x){
	if(x == 0)return 0;
	x->min = min(x->val, min(nmin(x->l), nmin(x->r)));
	x->size = 1 + size(x->l) + size(x->r);
	return x;
}


Node *merge(Node *a, Node *b){
	if(a == 0)return b;
	if(b == 0)return a;
	int asize = size(a);
	int bsize = size(b);

	if(rand() % (asize + bsize) < asize){
		Node *tmp = merge(a->r, b);
		a->r = tmp;
		return update(a);
	}
	else{
		Node *tmp = merge(a, b->l);
		b->l = tmp;
		return update(b);
	}
}

P split(Node *a, int pos){
	if(pos == 0)return P(0, a);
	if(pos == size(a))return P(a, 0);
	int lsize = size(a->l);
	if(lsize < pos){
		P tmp = split(a->r, pos - lsize - 1);
		a->r = tmp.first;
		tmp.first = update(a);
		return tmp;
	}
	else{
		P tmp = split(a->l, pos);
		a->l = tmp.second;
		tmp.second = update(a);
		return tmp;
	}
}

Node *shift(Node *a, int l, int r){
	P tmp = split(a, r);
	P tmp2 = split(tmp.first, l);
	P tmp3 = split(tmp.second, 1);
	tmp2.first = merge(tmp2.first, tmp3.first);
	tmp.first = merge(tmp2.first, tmp2.second);
	return merge(tmp.first, tmp3.second);	
}

int minval(Node *a, int l, int r){
	P tmp = split(a, r + 1);
	P tmp2 = split(tmp.first, l);
	int res = nmin(tmp2.second);
	tmp.first = merge(tmp2.first, tmp2.second);
	root = merge(tmp.first, tmp.second);
	return res;
}

Node *setval(Node *a, int pos, int val){
	P tmp = split(a, pos);
	tmp.second = split(tmp.second, 1).second;
	tmp.second = merge(new Node(val), tmp.second);
	return merge(tmp.first , tmp.second);
}
	
int main(){
        int n, q, x, y, z;
	cin >> n >> q;
	for(int i = 0;i < n;i++){
		cin >> x;
		root = merge(root, new Node(x));
	}
	for(int i = 0;i < q;i++){
		cin >> x >> y >> z;
		int l = y, r = z;

		if(x == 0){
			root = shift(root, l, r);
		}
		if(x == 1){
			cout << minval(root, l, r) << endl;
		}
		if(x == 2){
			root = setval(root, y, z);
		}
	}
	return 0;
}