#include <iostream>
#include <algorithm>
#include <cctype>
#include <vector>
#include <queue>
#include <cassert>
#include <ctime>
#include <tuple>
#include <string>
#define dump(x) std::cerr << __LINE__ << ":\t" #x " = " << x << std::endl

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

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

    static node *const NIL;

    node() {}

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

    node(const Key &key_, node *left_, node *right_, int size_, const Key &min_)
        : key(key_), 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(), nullptr, nullptr, 0, INF);

bool is_leaf(cnp n){
    return n->left == node::NIL;
}

class treap {
public:
    np root;


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

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

    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2099535#1
    treap(Key *left, Key *right) : root(__make_tree(left, right)) { }


    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2099535#1
    np __make_tree(Key *left, Key *right) {
        int sz = right - left;
        Key *mid = left + sz / 2;
        if (sz == 0){
            return node::NIL;
        } else if (sz == 1) {
            return new node(*mid, node::NIL, node::NIL, 1, *mid);
        } else {
            np lc = __make_tree(left, mid);
            np rc = __make_tree(mid, right);
            return new node(-1, lc, rc, sz, std::min(lc->min, rc->min));
        }
    }


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


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


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


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


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


    // 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); }


    // 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){
            // dump(l);
            // dump(r);
            // dump(n->size);
            // dump(n->min);
            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, r - sl));
        return res;
    }


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

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

    np __merge_sub(np l, np r) const {
        int sl = l->size, sr = r->size;
        int rand = node::xor128() % (sl + sr + 1);
        if (rand < sl){
            if(is_leaf(l)) return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
            l->right = __merge_sub(l->right, r);
            return __update(l);
        } else if(rand == sl) {
            return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
        } else {
            if(is_leaf(r)) return new node(-1, l, r, l->size + r->size, std::min(l->min, r->min));
            r->left = __merge_sub(l, r->left);
            return __update(r);
        }
    }

    np __merge(np l, np r) const {
        if(l == node::NIL) return r;
        if(r == node::NIL) return l;
        return __merge_sub(l, r);
    }

    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));
    }

    npair __split_at(np n, int k) const {
        if(n == node::NIL) return npair(node::NIL, node::NIL);
        else return __split_at_sub(n, k);
    }

    npair __split_at_sub(np n, int k) const {
        if (is_leaf(n)) {
            return k == 0 ? npair(node::NIL, n) : npair(n, node::NIL);
        } else if (k < n->left->size) {
            npair p = __split_at_sub(n->left, k);
            n->left = p.second;
            return npair(p.first, __update(n));
        } else if (k == n->left->size) {
            return npair(n->left, n->right);
        } else {
            npair p = __split_at_sub(n->right, k - n->left->size);
            n->right = p.first;
            return npair(__update(n), p.second);
        }
    }

    np __update(np n) const {
        assert(n->left != node::NIL);
        n->size = n->left->size + n->right->size + (n->left == node::NIL);
        n->min = std::min({ n->left->min, n->right->min, (n->left == node::NIL ? n->key : INF)});
        return n;
    }
    // np __update(np n) const {
    //     // assert(n->left != node::NIL);
    //     n->size = n->left->size + n->right->size;
    //     n->min = std::min(n->left->min, n->right->min);
    //     return n;
    // }

    void shift(int l, int r) {
        //std::cout << "shift " << l << ' ' << r << std::endl;
        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);
        np ac = __merge(a, c);
        np bd = __merge(b, d);
        root = __merge(ac, bd);
    }
};

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)

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) {
            cout << t.range_min(y, z + 1) << '\n';
        }
        if (x == 2) {
            t.set(y, z);
        }
    }
}

Measured memory_bytes: 28940