#include <bits/stdc++.h>

using Key = int;
const Key INF = 1e9;
const int MAX_N = 500010;  // ?????\????????° + EPS

struct node {
    Key key;
    int priority;
    node *left, *right;
    int size;
    Key min;

    static node *const NIL;

    node() {}

    node(const Key &x) : node(x, xor128(), NIL, NIL, 1, x) {}

    node(const Key &key_, int priority_, node *left_, node *right_, int size_, const Key &min_)
        : key(key_), priority(priority_), left(left_), right(right_), size(size_), min(min_) {}

    void *operator new(std::size_t) {
        static node pool[MAX_N];
        static int p = 0;
        return pool + p++;
    }

    static uint32_t xor128() {
        static uint32_t x = 123456789, y = 362436069, z = 521288629, w = time(0);
        uint32_t t = x ^ (x << 11);
        x = y;
        y = z;
        z = w;
        w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w;
    }
};

using np = node *;
using cnp = const node *;
using npair = std::pair<np, np>;

node *const node::NIL = new node(Key(), -1, nullptr, nullptr, 0, INF);

class treap {
protected:
    np root;

public:
    treap() : root(node::NIL) {}

    treap(np root_) : root(root_) {}

    treap(Key *left, Key *right) : root(node::NIL) {
        root = make_tree(left, right);
        int n = right - left;
        std::vector<int> ps(n);
        std::generate(ps.begin(), ps.end(), node::xor128); 
        std::sort(ps.begin(), ps.end());
        std::queue<np> que;
        que.push(root);
        while(que.size()){
            np n = que.front();
            que.pop();
            if(n == node::NIL) continue;
            ps.pop_back();
            n->priority = ps.back();
            que.push(n->left);
            que.push(n->right);
        }
    }

    np make_tree(Key *left, Key *right){
        int sz = right - left;
        if(sz == 0) return node::NIL;
        Key *mid = left + sz/2;
        np lc = make_tree(left, mid);
        np rc = make_tree(mid + 1, right);
        return new node(*mid, -1, lc, rc, sz, std::min({lc->min, *mid, rc->min}));
    }

public:
    int size() const { return root->size; }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void set(int k, const Key &x) { __set(root, k, x); }

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void __set(np n, int k, const Key &x) {
        if (k < n->left->size)
            __set(n->left, k, x);
        else if (n->left->size == k)
            n->key = x;
        else
            __set(n->right, k - n->left->size - 1, x);
        __update(n);
    }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key get(int k) const { return __get(root, k); }

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key __get(np n, int k) const {
        if (k < n->left->size)
            return __get(n->left, k);
        else if (n->left->size == k)
            return n->key;
        else
            return __get(n->right, k - n->left->size - 1);
    }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key range_min(int l, int r) { return __range_min(root, l, r); }

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    Key __range_min(cnp n, int l, int r) const {
        l = std::max(l, 0);
        r = std::min(r, n->size);
        if (l >= r) return INF;
        if (l == 0 && r == n->size) return n->min;
        Key res = INF;
        int sl = n->left->size;
        res = std::min(res, __range_min(n->left, l, r));
        res = std::min(res, __range_min(n->right, l - sl - 1, r - sl - 1));
        if (l <= sl && sl < r) res = std::min(res, n->key);
        return res;
    }

public:
    void merge_from_left(treap &t) { root = __merge(t.root, root); }

    void merge_from_right(treap &t) { root = __merge(root, t.root); }

protected:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    np __merge(np l, np r) const {
        if (l == node::NIL) return r;
        if (r == node::NIL) return l;
        if (l->priority > r->priority) {
            l->right = __merge(l->right, r);
            return __update(l);
        } else {
            r->left = __merge(l, r->left);
            return __update(r);
        }
    }

public:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    std::pair<treap, treap> split_at(int k) {
        np l, r;
        std::tie(l, r) = __split_at(root, k);
        return std::make_pair(treap(l), treap(r));
    }

protected:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    npair __split_at(np n, int k) const {
        if (n == node::NIL) return {node::NIL, node::NIL};
        if (k <= n->left->size) {
            npair p = __split_at(n->left, k);
            n->left = p.second;
            return npair(p.first, __update(n));
        } else {
            npair p = __split_at(n->right, k - n->left->size - 1);
            n->right = p.first;
            return npair(__update(n), p.second);
        }
    }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void insert_at(const Key &x, int k) { root = __insert_at(root, x, k); }

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    np __insert_at(np n, const Key &x, int k) const {
        np l, r;
        std::tie(l, r) = __split_at(n, k);
        return __merge(__merge(l, new node(x)), r);
    }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void erase_at(int k) { root = __erase_at(root, k); }

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    np __erase_at(np n, int k) const {
        np l, r, m;
        std::tie(l, r) = __split_at(n, k);
        std::tie(r, m) = __split_at(r, 1);
        return __merge(l, r);
    }

public:
    const Key &front() const {
        assert(root != node::NIL);
        return __front(root)->key;
    }

protected:
    cnp __front(cnp n) const { return n->left != node::NIL ? __front(n->left) : n; }

public:
    const Key &back() const {
        assert(root != node::NIL);
        return __back(root)->key;
    }

protected:
    cnp __back(cnp n) const { return n->right != node::NIL ? __back(n->right) : n; }

public:
    Key front() {
        assert(root != node::NIL);
        return __front(root)->key;
    }

protected:
    np __front(np n) const { return n->left != node::NIL ? __front(n->left) : n; }

public:
    Key back() {
        assert(root != node::NIL);
        return __back(root)->key;
    }

protected:
    np __back(np n) const { return n->right != node::NIL ? __back(n->right) : n; }

public:
    void push_front(const Key &x) {
        root = __merge(new node(x, node::xor128(), node::NIL, node::NIL, 1, x), root);
    }

    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083288
    void push_back(const Key &x) {
        root = __merge(root, new node(x, node::xor128(), node::NIL, node::NIL, 1, x));
    }

    void pop_front() {
        assert(root->size != 0);
        root = __split_at(root, 1).first;
    }

    void pop_back() {
        assert(root->size != 0);
        root = __split_at(root, root->size - 1).second;
    }

protected:
    np __update(np n) const {
        n->size = 1 + n->left->size + n->right->size;
        n->min = std::min({n->left->min, n->key, n->right->min});
        return n;
    }

public:
    std::string to_string() const {
        std::string res;
        __to_string(root, res);
        return res;
    }

protected:
    void __to_string(cnp n, std::string &res) const {
        res += "(";
        if(n != node::NIL) {
            __to_string(n->left, res);
            res += ")" + std::to_string(n->key) + "(";
            __to_string(n->right, res);
        }
        res += ")";
    }

    public:
    void shift(int l, int r) {
        np a, b, c, d;
        std::tie(a, b) = __split_at(root, l);
        std::tie(b, c) = __split_at(b, r - l);
        std::tie(c, d) = __split_at(c, 1);
        root = __merge(__merge(a, c), __merge(b, d));
    }
};

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) std::cerr << __LINE__ << ":\t" #x " = " << x << std::endl
 
 
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
 
    int n, q;
    cin >> n >> q;
 
    static int a[200010];
    for (int i = 0; i < n; i++) cin >> a[i];
    treap t(a, a+n);

    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x == 0) {
            t.shift(y, z);
        }
        if (x == 1) {
            //puts("=====");
            //Treap::show(root);
            cout << t.range_min(y, z + 1) << '\n';
        }
        if (x == 2) {
            t.set(y, z);
        }
    }
}

Measured memory_bytes: 11880