#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

template<typename T, typename F> struct Treap{

    int gen(){
        static int x = 123456789;
        static int y = 362436069;
        static int z = 521288629;
        static int w = 88675123;
        int t;

        t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    }

    struct Node{
        Node *l_ptr, *r_ptr;
        int sz, pri;
        T val, sum;
        Node(): l_ptr(nullptr), r_ptr(nullptr), sz(1), pri(0), val(T{}), sum(T{}){}
    };

    int n;
    vector<Node> nodes;
    F f;

    Treap(int n, T et, F f): n(n), f(f){
        nodes.resize(n);
        rep(i, n){
            nodes[i].val = nodes[i].sum = et;
        }
    }

    int size(Node *node){
        return node ? node->sz : 0;
    }

    void pull(Node *node){
        node->sz = size(node->l_ptr) + 1 + size(node->r_ptr);
        node->sum = node->val;
        if(node->l_ptr){
            node->sum = f(node->l_ptr->sum, node->sum);
        }
        if(node->r_ptr){
            node->sum = f(node->sum, node->r_ptr->sum);
        }
    }

    Node *merge(Node *l_node, Node *r_node){
        if(!l_node || !r_node) return l_node ? l_node : r_node;
        if(l_node->pri > r_node->pri){
            r_node->l_ptr = merge(l_node->r_ptr, r_node->l_ptr);
            l_node->r_ptr = r_node;
            pull(r_node);
            pull(l_node);
            return l_node;
        }
        else{
            l_node->r_ptr = merge(l_node->r_ptr, r_node->l_ptr);
            r_node->l_ptr = l_node;
            pull(l_node);
            pull(r_node);
            return r_node;
        }
    }

    pair<Node *, Node *> split(Node * node, int K){
        if(!node) return {node, node};
        if(size(node->l_ptr) >= K){
            auto p = split(node->l_ptr, K);
            node->l_ptr = p.se;
            pull(node);
            return {p.fi, node};
        }
        else{
            auto p = split(node->r_ptr, K-size(node->l_ptr)-1);
            node->r_ptr = p.fi;
            pull(node);
            return {node, p.se};
        }
    }

    Node *build(vector<int> &a, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r-l == 0) return nullptr;
        else if(r-l == 1){
            nodes[l].pri = gen();
            nodes[l].val = nodes[l].sum = a[l];
            return &nodes[l];
        }
        else{
            return merge(build(a, l, (l+r)/2), build(a, (l+r)/2, r));
        }
    }

    pair<Node *, T> get_sum(Node *root, int l, int r){
        Node *l_root, *r_root;
        tie(l_root, r_root) = split(root, r);
        tie(l_root, root) = split(l_root, l);
        T ret = root->sum;
        root = merge(merge(l_root, root), r_root);
        return {root, ret};
    }

    Node *set_val(Node *node, int K, T x){
        if(size(node->l_ptr) == K) node->val = x;
        else if(size(node->l_ptr) > K) set_val(node->l_ptr, K, x);
        else set_val(node->r_ptr, K-size(node->l_ptr)-1, x);
        pull(node);
        return node;
    }

    Node *shiftr(Node *root, int l, int r){
        auto t = split(root, r);
        Node *a, *b, *c, *d;
        tie(a, b) = split(t.fi, l);
        tie(c, d) = split(t.se, 1);
        return merge(merge(a, c), merge(b, d));
    }
};

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    auto f = [](int x, int y){return min(x, y);};
    Treap<int, decltype(f)> st(n, mod, f);
    vector<int> a(n);
    rep(i, n) scanf("%d", &a[i]);
    auto root = st.build(a);

    rep(_, q){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        if(x == 0){
            root = st.shiftr(root, y, z);
        }
        else if(x == 1){
            int ans;
            tie(root, ans) = st.get_sum(root, y, z+1);
            printf("%d\n", ans);
        }
        else{
            root = st.set_val(root, y, z);
        }
    }
}


Measured memory_bytes: 9984