#include <tuple>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>

using Key = int;
const Key INF = 1e9;

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[200010];
        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 pair = 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_) { }

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

protected:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083278
    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:
    Key get(int k) const {
        return __get(root, k);
    }

protected:
    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=2083278
    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=2083278
    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
    pair __split_at(Np n, int k) const {
        if (n == Node::NIL) return{ Node::NIL, Node::NIL };
        if (k <= n->left->size) {
            pair p = __split_at(n->left, k);
            n->left = p.second;
            return pair(p.first, __update(n));
        } else {
            pair p = __split_at(n->right, k - n->left->size - 1);
            n->right = p.first;
            return pair(__update(n), p.second);
        }
    }

public:
    void insert_at(const Key &x, int k) {
        root = __insert_at(root, x, k);
    }

protected:
    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:
    void erase_at(int k) {
        root = __erase_at(root, k);
    }

protected:
    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(CNp n) const {
        assert(n != 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(CNp n) {
        assert(n != 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(Key k) {
        root = __merge(new Node(k, Node::xor128(), Node::NIL, Node::NIL, 1, k), root);
    }

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

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

    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083278
    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));
    }

    void shift2(int l, int r) {
        Key x = __get(root, r);
        root = __erase_at(root, r);
        root = __insert_at(root, l, x);
    }
};

// ??????????????????????????????
class ordered_set : public treap {
public:
    ordered_set() : treap() {}
    ordered_set(Node *n) : treap(n) {}

public:    
    std::pair<ordered_set, ordered_set> split_at(int k) {
        Np l, r;
        std::tie(l, r) = __split_at(root, k);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }
    
public:
    std::pair<ordered_set, ordered_set> split_less(const Key &x) {
        Np l, r;
        std::tie(l, r) = __split_less(root, x);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }

protected:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    pair __split_less(Np n, const Key &x) const {
        if (n == Node::NIL) return pair(Node::NIL, Node::NIL);
        if (n->key < x) {
            pair p = __split_less(n->right, x);
            n->right = p.first;
            return pair(__update(n), p.second);
        } else {
            pair p = __split_less(n->left, x);
            n->left = p.second;
            return pair(p.first, __update(n));
        }
    }

public:
    std::pair<ordered_set, ordered_set> split_leq(const Key &x) {
        Np l, r;
        std::tie(l, r) = __split_leq(root, x);
        return std::make_pair(ordered_set(l), ordered_set(r));
    }

protected:
    pair __split_leq(Np n, const Key &x) const {
        if (n == Node::NIL) return pair(Node::NIL, Node::NIL);
        if (n->key <= x) {
            pair p = __split_leq(n->right, x);
            n->right = p.first;
            return pair(__update(n), p.second);
        } else {
            pair p = __split_leq(n->left, x);
            n->left = p.second;
            return pair(p.first, __update(n));
        }
    }

public:
    void insert(const Key &x) {
        root = __insert(root, x);
    }

protected:
    Np __insert(Np n, const Key &x) const {
        Np l, r;
        std::tie(l, r) = __split_less(n, x);
        return __merge(__merge(l, new Node(x)), r);
    }

public:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    void erase_one(const Key &x) {
        assert(includes(x));
        root = __erase_one(root, x);
    }

protected:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    Np __erase_one(Np n, const Key &x) const {
        Np l, m, r;
        std::tie(l, r) = __split_less(n, x);
        std::tie(m, r) = __split_at(r, 1);
        return __merge(l, r);
    }

public:
    void erase_all(const Key &x) {
        root = __erase_one(root, x);
    }

protected:
    Np __erase_all(Np n, const Key &x) const {
        Np l, m, r;
        std::tie(l, r) = __split_less(n, x);
        std::tie(m, r) = __split_leq(r, x);
        return __merge(l, r);
    }

public:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    int count_less(const Key &x) const {
        return __count_less(root, x);
    }

protected:
    // yukicoder 449 http://yukicoder.me/submissions/131855
    int __count_less(CNp n, const Key &x) const {
        if(n == Node::NIL) return 0;
        if(n->key < x){
            return n->left->size + 1 + __count_less(n->right, x);
        } else {
            return __count_less(n->left, x);
        }
    }

public:
    int count_leq(const Key &x) const {
        return __count_leq(root, x);
    }

protected:
    int __count_leq(CNp n, const Key &x) const {
        if(n == Node::NIL) return 0;
        if(n->key <= x){
            return n->left->size + 1 + __count_leq(n->right, x);
        } else {
            return __count_less(n->left, x);
        }
    }

public:
    int count(const Key &x) const {
        return count_leq(x) - count_less(x);
    }

public:
    // AOJ 1508 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2083278
    bool includes(const Key &x) const {
        return __includes(root, x);
    }

protected:
    
    bool __includes(Np n, const Key &x) const {
        if(n == Node::NIL) return false;
        else if(n->key < x) return __includes(n->right, x);
        else if(n->key == x) return true;
        else return __includes(n->left, x);
    }

public:
    Key lower_bound(const Key &x) const {
        return __lower_bound(root, x)->key;
    }

protected:
    Np __lower_bound(Np n, const Key &x) const {
        if(n == Node::NIL) return Node::NIL;
        if(n->key <= x){
            Np res = __lower_bound(n->left, x);
            return res != Node::NIL ? res : n;
        } else {
            return __lower_bound(n->right, x);
        }
    }

public:
    Key upper_bound(const Key &x) const {
        return __upper_bound(root, x)->key;
    }

protected:
    Np __upper_bound(Np n, const Key &x) const {
        if(n == Node::NIL) return Node::NIL;
        if(n->key < x){
            Np res = __upper_bound(n->left, x);
            return res != Node::NIL ? res : n;
        } else {
            return __upper_bound(n->right, x);
        }
    }
};


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

    treap t;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        t.push_back(a);
    }

    //Treap::show(root);

    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: 9480