#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;

template <typename T> class Treap
{
    function<double(void)> dice;
public:
    struct node{
        T val, min_val;
        int st_size;   // ??¨?????¨????????????
        double  pri;   // ?????????
        node* left; node* right;
        using pnn = pair<node*,node*>;
        node(T v, double p) : val(v), left(nullptr), right(nullptr), pri(p), st_size(1), min_val(v){}
        ~node() { delete left; delete right; }
        static int size(node* t) { return t ? t->st_size : 0; }
        static T min_(node* t) { return t ? t->min_val : std::numeric_limits<T>::max(); }
        static 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;
        }
        static node* merge(node* l, node* r){   //??????????????????????????°??????????????????
            if (!l || !r) return (!l) ? r : l;
            update(l); update(r);
            if (l->pri > r->pri){
                l->right = merge(l->right, r);
                return update(l);
            }else{
                r->left = merge(l, r->left);
                return update(r);
            }
        }
        static 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);
            }
        }
        static node* insert(node* t, int k, node* u){
            pnn s = split(t, k);
            return merge(merge(s.first, u), s.second);
        }
        static 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);
        }
    };
    node *root;
    Treap() : root(nullptr) {
        random_device rnd;
        dice = std::bind(std::uniform_real_distribution<double>(0.0,1.0), std::mt19937(rnd()));
    }
    ~Treap() {}
    void insert(int k, T val){
        root = node::insert(root, k, new node(val, dice()));
    }
    void erase(int k) {
        node *p;
        tie(root, p) = node::erase(root, k);
        p->left = p->right = nullptr;
        delete p;
    }
    int size() const { return node::size(root); }
    T get(int k){
        node* v = root;
        while(v) {
            int s = node::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;
    }
    //cri??\??????????´???°(???????????????????????§????????´??????????????¨???)
    int index(T cri){
        int res = 0;
        node* v = root;
        while(v){
            if(cri < v->val){
                v = v->left;
            }else{
                res += node::size(v->left) + 1;
                v = v->right;
            }
        }
        return res;
    }
    //k???????????????val????????´
    void set(int k, T val) {
        auto sr = node::split(root, k+1);
        auto sl = node::split(sr.first, k);
        auto lr = sl.second;
        lr->val = val;
        root = node::merge(node::merge(sl.first, lr), sr.second);
    }
    //???????????§?????°?????????
    void shift(int l,int r)
    {
        auto sr = node::split(root, r);
        auto sl = node::split(sr.first, l);
        auto sm = node::split(sl.second, r-l-1);
        root = node::merge(node::merge(sl.first,sm.second),node::merge(sm.first,sr.second));
    }
    T query(int l, int r) {
        auto sr = node::split(root, r);
        auto sl = node::split(sr.first, l);
        auto lr = sl.second;
        T val = node::min_(lr);
        root = node::merge(node::merge(sl.first, lr), sr.second);
        return val;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    Treap<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: 12576