#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll inf = 3e18;
const char sp = ' ';

struct treap {
	treap *lch, *rch;
	int val, min, pri, cnt;
	treap() {};
	treap(int v, int p) {
		val = min = v;
		pri = p;
		lch = rch = NULL;
		cnt = 1;
	}
};

int count(treap *t) {
	if (!t)return 0;
	return t->cnt;
}

int minimum(treap *t) {
	if (!t)return 200000000;
	return t->min;
}

treap* update(treap* t) {
	t->min = min({ t->val,minimum(t->lch),minimum(t->rch) });
	t->cnt = count(t->lch) + count(t->rch) + 1;
	return t;
}

treap* merge(treap* l, treap* r) {
	if (!l)return r;
	if (!r)return l;
	if (l->pri > r->pri) {
		l->rch = merge(l->rch, r);
		return update(l);
	}
	else {
		r->lch = merge(l, r->lch);
		return update(r);
	}
}

pair<treap*, treap*> split(treap* t, int c) {
	//[t,t+c)
	if (!t) {
		return { NULL,NULL };
	}
	if (count(t->lch) >= c) {
		auto p = split(t->lch, c);
		t->lch = p.second;
		return { p.first,update(t) };
	}
	else {
		auto p = split(t->rch, c - count(t->lch) - 1);
		t->rch = p.first;
		return { update(t),p.second };
	}
}

treap* insert(treap* t, treap* u,int c) {
	// [0,c)
	auto p = split(t, c);
	return merge(merge(p.first, u), p.second);
}

pair<treap*, treap*> erase(treap* t, int c) {
	//[0,c)[c,N)
	auto p = split(t, c);
	//[c,c+1),[c+1,N)
	auto q = split(p.second, 1);
	return { merge(p.first,q.second),q.first };
}

int n, q, a;
treap tree[200000];
mt19937 mt(869120);

int main() {
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> a;
		tree[i] = treap(a, uniform_int_distribution<>(0, 2000000000)(mt));
	}
	treap *root = tree;
	for (int i = 1; i < n; i++) {
		root = merge(root, tree + i);
	}
	for (int i = 0; i < q; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		if (x == 0) {
			auto p = erase(root, z);
			root = insert(p.first, p.second, y);
		}
		else if (x == 1) {
			auto p = split(root, z + 1);
			auto q = split(p.first, y);
			cout << q.second->min << endl;
			root = merge(merge(q.first, q.second), p.second);
		}
		else {
			auto p = erase(root, y);
			p.second->val = z;
			update(p.second);
			root = insert(p.first, p.second, y);
		}
	}
}
