#define NDEBUG
 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <cassert>
   
using namespace std;
typedef long long ll;
 
template<class D>
struct AASSTree {
    struct Node;
    typedef Node* NP;
    const static D INF = 1<<30;
    static Node last_d;
    static NP last;
    struct Node {
        NP l, r;
        int level, sz;
        D v, mi, lz;
        Node(): l(nullptr), r(nullptr), level(0), sz(0) {}
        Node(D vv): l(last), r(last), level(1), sz(1) {
            v = vv;
            mi = vv;
            lz = 0;
        }

        //メモリプールをしたい時のためにnewにはラッパを用意しておく
        static NP make() {
            return new Node();
        }
        static NP make(D vv) {
            return new Node(vv);
        }

        //k番目の要素のポインタを取得する
        NP at_ptr(int k) {
            if (k == l->sz) return this;
            push();
            if (k < l->sz) {
                return l->at_ptr(k);
            } else {
                return r->at_ptr(k - (l->sz+1));
            }
        }

        void update() {
            sz = 1+l->sz+r->sz;
            assert(!lz);
            mi = v;
            if (l != last) {
                mi = min(mi, l->mi);
            }
            if (r != last) {
                mi = min(mi, r->mi);
            }
        }
        void push() {
            if (lz) {
                if (l != last) {
                    l->lzdata(lz);
                }
                if (r != last) {
                    r->lzdata(lz);
                }
                lz = 0;
            }
        }
        void lzdata(D x) {
            v += x;
            mi += x;
            lz += x;
        }
        D at(int k) {
            if (k == l->sz) return v;
            push();
            if (k < l->sz) {
                return l->at(k);
            } else {
                return r->at(k - (l->sz+1));
            }
        }
        void tp() {
            if (!sz) return;
            push();
            l->tp();
            cout << v << " ";
            r->tp();
        }

        void add(int a, int b, D x) {
            if (!sz || b <= 0 || sz <= a) return;
            if (a <= 0 && sz <= b) {
                lzdata(x);
                return;
            }
            push();
            l->add(a, b, x);
            if (a <= l->sz && l->sz < b) {
                v += x;
            }
            r->add(a - (l->sz+1), b - (l->sz+1), x);
            update();
        }
        D get(int a, int b) {
            if (!sz || b <= 0 || sz <= a) return INF;
            if (a <= 0 && sz <= b) {
                return mi;
            }
            push();
            D res = INF;
            res = min(res, l->get(a, b));
            if (a <= l->sz && l->sz < b) {
                res = min(res, v);
            }
            res = min(res, r->get(a - (l->sz+1), b - (l->sz+1)));
            return res;
        }
        void set(int k, D x) {
            if (k == l->sz) {
                v = x;
                update();
                return;
            }
            if (k < l->sz) {
                l->set(k, x);
            } else {
                r->set(k - (l->sz+1), x);
            }
            update();
            return;
        }
        void allpush() {
            if (!sz) return;
            push();
            l->allpush();
            r->allpush();
        }
    } *n;
    static NP built(int sz, D d[]) {
        if (!sz) return last;
        int md = (sz-1)/2;
        NP n = Node::make(d[md]);
        n->l = built(md, d);
        n->r = built(sz-(md+1), d+(md+1));
        n->level = n->l->level+1;
        n->update();
        return n;
    }
    AASSTree() : n(last) {}
    AASSTree(NP n) : n(n) {}
    //木の初期化はn回insertより一気に作る方が有意に速くなる事が多い
    AASSTree(int sz, D d[]) {
        n = built(sz, d);
    }

    //AA木の基本動作であるskew/split splitは名前が紛らわしいためpullに変更してある
    static NP skew(NP n) {
        if (n->level == n->l->level) {
            NP L = n->l;
            n->push(); L->push();
            n->l = L->r;
            L->r = n;
            n->update(); L->update();
            return L;
        }
        return n;
    }
    static NP pull(NP n) {
        if (n->level == n->r->level && n->r->level == n->r->r->level) {
            NP R = n->r;
            n->push(); R->push();
            n->r = R->l;
            R->l = n;
            R->level++;
            n->update(); R->update();
            return R;
        }
        return n;
    }

    static NP insert(NP n, int k, D x) {
        if (n == last) {
            assert(k == 0);
            return Node::make(x);
        }
        n->push();
        if (k <= n->l->sz) {
            n->l = insert(n->l, k, x);
            n->update();
        } else {
            n->r = insert(n->r, k - (n->l->sz+1), x);
            n->update();
        }
        n = skew(n);
        n = pull(n);
        return n;
    }
    static NP leftdown(NP n) {
        assert(n->l->level < n->level);
        if (n->l->level == n->level-1) return n;
        n->level--;
        if (n->r->level == n->level) {
            n = pull(n);
        } else {
            n->r->level--;
            n->r = skew(n->r);
            n->r->r = skew(n->r->r);
            n = pull(n);
            n->r = pull(n->r);
        }
        return n;
    }
    static NP rightdown(NP n) {
        assert(n->r->level <= n->level);
        if (n->r->level >= n->level-1) return n;
        n->level--;
        n = skew(n);
        n->r = skew(n->r);
        n = pull(n);
        return n;
    }
    static NP superleftdown(NP n) {
        if (n->l->level == n->level-1) return n;
        if (n->level != n->r->level && n->r->level != n->r->r->level) {
            n->level--;
            return superleftdown(n);
        }
        n = leftdown(n);
        n->l = superleftdown(n->l);
        n = leftdown(n);
        return n;
    }
    static NP superrightdown(NP n) {
        if (n->r->level >= n->level-1) return n;
        n = rightdown(n);
        n->r = superrightdown(n->r);
        n = rightdown(n);
        return n;
    }

    //pair<0番目の要素,0番目の要素を削除した木>
    static pair<NP, NP> at0_with_remove(NP n) {
        n->push();
        if (n->l == last) {
            return {n, n->r};
        }
        auto x = at0_with_remove(n->l);
        n->l = x.second;
        n->update();
        x.second = leftdown(n);
        return x;
    }
    static NP remove(NP n, int k) {
        assert(n != last);
        n->push();
        if (k == n->l->sz) {
            if (n->level == 1) {
                return n->r;
            }
            auto x = at0_with_remove(n->r);
            NP nn = x.first;
            nn->push();
            nn->l = n->l;
            nn->r = x.second;
            nn->level = n->level;
            nn->update();
            return rightdown(nn);
        }
        if (k < n->l->sz) {
            n->l = remove(n->l, k);
            n->update();
            return leftdown(n);
        } else {
            n->r = remove(n->r, k - (n->l->sz+1));
            n->update();
            return rightdown(n);
        }
    }
    static NP merge(NP l, NP r) {
        if (l == last) return r;
        if (r == last) return l;
        if (l->level == r->level) {
            auto x = at0_with_remove(r);
            NP n = x.first;
            n->push();
            n->r = x.second;
            n->l = l;
            n->level = l->level+1;
            n->update();
            return rightdown(n);
        }
        NP n;
        l->push(); r->push();
        if (l->level > r->level) {
            l->push();
            l->r = merge(l->r, r);
            l->update();
            n = l;
        } else {
            r->push();
            r->l = merge(l, r->l);
            r->update();
            n = r;
        }
        n = skew(n);
        n = pull(n);
        return n;
    }
    static pair<NP, NP> split(NP n, int k) {
        if (n == last) return {last, last};
        n->push();
        if (k <= n->l->sz) {
            auto y = split(n->l, k);
            n->l = y.second;
            n->update();
            n = superleftdown(n);
            y.second = n;
            return y;
        } else {
            auto y = split(n->r, k- (n->l->sz+1));
            n->r = y.first;
            n->update();
            n = superrightdown(n);
            y.first = n;
            return y;
        }
    }

    int sz() {
        return n->sz;
    }
    //基本動作
    void merge(AASSTree r) {
        n = merge(n, r.n);
    }
    AASSTree split(int k) {
        auto y = split(n, k);
        n = y.first;
        return AASSTree(y.second);
    }
    void insert(int k, D x) {
        n = insert(n, k, x);
    }
    void remove(int k) {
        n = remove(n, k);
    }
    D at(int k) {
        return n->at(k);
    }
    void tp() {
        n->tp();
        printf("\n");
    }
    void add(int l, int r, D x) {
        n->add(l, r, x);
    }
    void set(int k, D x) {
        n->set(k, x);
    }
    D get(int l, int r) {
        auto t2 = split(r);
        auto t1 = split(l);
        //t - t1 - t2
        auto tmp = t1.n->mi;
        merge(t1); merge(t2);
//        return n->get(l, r);
        return tmp;
    }
    void allpush() {
        n->allpush();
        return;
    }
};
template<class D>
typename AASSTree<D>::Node AASSTree<D>::last_d = AASSTree<D>::Node();
template<class D>
typename AASSTree<D>::NP AASSTree<D>::last = &AASSTree<D>::last_d;

const int MN = 200200;
int a[MN];
int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 0; i < n; i++) {
        scanf("%d", a+i);
    }
    AASSTree<int> atr(n, a);
    for (int i = 0; i < q; i++) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        if (x == 0) {
            int l = y, r = z;
            int tmp = atr.at(r);
            atr.remove(r);
            atr.insert(l, tmp);
        } else if (x == 1) {
            int l = y, r = z; r++;
            printf("%d\n", atr.get(l, r));
        } else {
            int l = y, val = z;
            atr.set(l, val);
        }
        //atr.tp();
    }
    return 0;
}

Measured memory_bytes: 20736