#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template <typename T> class RBST
{
public:
    struct node{
        T val, min_val;
        int st_size;   // ??¨?????¨????????????
        node* left; node* right;
        node(T v) : val(v), left(nullptr), right(nullptr), st_size(1), min_val(v){}
        ~node() { delete left; delete right; }
    };
    node *root;
    using pnn = pair<node*,node*>;
    RBST() : root(nullptr) {}
    ~RBST() {}
    int size(node* t) { return t ? t->st_size : 0; }
    T min_(node* t) { return t ? t->min_val : std::numeric_limits<T>::max(); }
    node* update(node *t) {
        node* l = t->left; node* r = t->right;
        t->st_size = size(l) + size(r) + 1;
        t->min_val = min({min_(l), min_(r), t->val});
        return t;
    }
    unsigned rnd(){
        static unsigned x = 123456789, y = 362436069, z = 521288629, w = 86675;
        unsigned t = (x^(x<<11));
        x = y,y = z,z = w;
        return (w = (w^(w>>19))^(t^(t>>8)));
    }
    node* merge(node* l, node* r){
        if (!l || !r) return (!l) ? r : l;
        update(l); update(r);
        if(rnd() % (size(l) + size(r)) < (unsigned)size(l)){
            l->right = merge(l->right, r);
            return update(l);
        }else{
            r->left = merge(l, r->left);
            return update(r);
        }
    }
    pnn split(node* t, int k){   //??¨???????????????(k,n-k)??¨???????????????????????????
        if(!t) return pnn(nullptr, nullptr);
        update(t);
        if(k <= size(t->left)){
            pnn s = split(t->left, k);
            t->left = s.second;
            return pnn(s.first,update(t));
        }else{
            pnn s = split(t->right, k-size(t->left)-1);
            t->right = s.first;
            return pnn(update(t), s.second);
        }
    }
    node* insert(node* t, int k, node* u){
        pnn s = split(t, k);
        return merge(merge(s.first, u), s.second);
    }
    pnn erase(node* t, int k){
        pnn sr = split(t, k+1);
        pnn sl = split(sr.first, k);
        return pnn(merge(sl.first, sr.second), sl.second);
    }
    void insert(int k, T val){
        root = insert(root, k, new node(val));
    }
    void erase(int k) {
        node *p;
        tie(root, p) = erase(root, k);
        p->left = p->right = nullptr;
        delete p;
    }
    T get(int k){
        node* v = root;
        while(v) {
            int s = size(v->left);
            if(s > k){
                 v = v->left;
            }else if(s == k){
                return v->val;
            }else{
                v = v->right;
                k -= s+1;
            }
        }
        return v->val;
    }
    //k???????????????val????????´
    void set(int k, T val) {
        auto sr = split(root, k+1);
        auto sl = split(sr.first, k);
        auto lr = sl.second;
        lr->val = val;
        root = merge(merge(sl.first, lr), sr.second);
    }
    //???????????§?????°?????????
    void shift(int l,int r)
    {
        auto sr = split(root, r);
        auto sl = split(sr.first, l);
        auto sm = split(sl.second, r-l-1);
        root = merge(merge(sl.first,sm.second),merge(sm.first,sr.second));
    }
    T query(int l, int r) {
        auto sr = split(root, r);
        auto sl = split(sr.first, l);
        auto lr = sl.second;
        T val = min_(lr);
        root = merge(merge(sl.first, lr), sr.second);
        return val;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    RBST<int> tr;
    rep(i,n){
        int a;
        cin >> a;
        tr.insert(i,a);
    }
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0){
            tr.shift(b,c+1);
        }else if(a == 1){
            cout << tr.query(b,c+1) << "\n";
        }else{
            tr.set(b,c);
        }
    }
    return 0;
}

Measured memory_bytes: 12580