#include <utility>
#include <cassert>
#include <set>
using namespace std;

template<class T>
struct splay_array {
  struct node {
    node* left;
    node* right;
    node* parent;
    T val;
    T rmq;
    size_t size;
    node(T v) : val(v),rmq(v), left(nullptr), right(nullptr), parent(nullptr){}
    ~node() {
      delete left , left = nullptr;
      delete right , right = nullptr;
    }
  };
private:
  size_t subtree_size(node* x) {
    if(x) return x->size;
    return 0;
  }
  T rmq(node* x) {
    if(!x) return 1e9;
    return x->rmq;
  }
  node* fix(node* n) {
    if(!n) return nullptr;
    n->size = subtree_size(n->left) + subtree_size(n->right) + 1;
    n->rmq = std::min(std::min(rmq(n->left), n->val), rmq(n->right));
    return n;
  }
  void setl(node* par, node* x) {
    if(par) par->left = x;
    if(x) x->parent = par;
    fix(par);
  }
  void setr(node* par, node* x) {
    if(par) par->right = x;
    if(x) x->parent = par;
    fix(par);
  }
  void zig(node* x) {
    node* p = x->parent;
    setl(p, x->right);
    if(p->parent) {
      if(p->parent->left == p) setl(p->parent, x);
      else setr(p->parent, x);
    }
    else x->parent = nullptr;
    setr(x, p);
  }
  void zag(node* x) {
    node* p = x->parent;
    setr(p, x->left);
    if(p->parent) {
      if(p->parent->left == p) setl(p->parent, x);
      else setr(p->parent, x);
    }
    else x->parent = nullptr;
    setl(x, p);
  }
  node* splay(node* x) {
    if(!x) return nullptr;
    while(x->parent) {
      if(!x->parent->parent){
        if(x->parent->left == x) zig(x);
        else zag(x);
      }
      else if(x->parent->parent->left == x->parent && x->parent->left == x){
        zig(x->parent);
        zig(x);
      }
      else if(x->parent->parent->left == x->parent && x->parent->right == x){
        zag(x);
        zig(x);
      }
      else if(x->parent->parent->right == x->parent && x->parent->right == x){
        zag(x->parent);
        zag(x);
      }
      else{
        zig(x);
        zag(x);
      }
    }
    return x;
  }

  node* find(node* r, size_t i) {
    assert(0 <= i);
    assert(i < subtree_size(r));
    node* z = r;
    while(z){
      if(subtree_size(z->left) == i){
        return splay(z);
      }
      else if(subtree_size(z->left) < i){
        i -= subtree_size(z->left) + 1;
        z = z->right;
      }
      else{
        z = z->left;
      }
    }
    assert(false);
  }

  pair<node*,node*> split(node* r, size_t i) {
    assert(0 <= i);
    assert(i <= subtree_size(r));
    if(i == 0) return {nullptr, r};
    if(i == subtree_size(r)) return {r, nullptr};
    r = find(r, i - 1);
    node* y = r->right;
    if(y) y->parent = nullptr;
    r->right = nullptr;
    fix(r);
    return {r, y};
  }

  node* merge(node* r1, node* r2) {
    if(!r1) {
      r1 = r2;
    }
    else if(!r2) {
    }
    else {
      size_t sz = subtree_size(r1);
      r1 = find(r1, sz - 1);
      setr(r1,r2);
    }
    return r1;
  }

  node* root;
public:
  using sarr = splay_array<T>;
  splay_array() : root(nullptr) {}
  splay_array(node* r) : root(r) {}
  splay_array(splay_array&& arr) {
    root = arr.root;
    arr.root = nullptr;
  }
  splay_array& operator=(splay_array&& arr) {
    root = arr.root;
    arr.root = nullptr;
    return *this;
  }
  ~splay_array() { delete root; }
  pair<sarr,sarr> split(size_t i) {
    pair<node*,node*> p = split(root, i);
    root = nullptr;
    return {sarr(p.first), sarr(p.second)};
  }
  void merge(sarr&& arr) {
    root = merge(root, arr.root);
    arr.root = nullptr;
  }
  void insert(size_t i, T val) {
    node* x = new node(val);
    auto p = split(root, i);
    setl(x, p.first);
    setr(x,p.second);
    root = x;
  }
  void erase(size_t i) {
    auto p = split(root, i + 1);
    auto q = split(p.first, i);
    fix(q.first);
    fix(p.second);
    if(p.first) {
      p.first->left = nullptr;
      p.first->right = nullptr;
      delete p.first, p.first = nullptr;
    }
    root = merge(q.first, p.second);
    fix(root);
  }
  T at(size_t i) {
    return (root = find(root,i))->val;
  }
  void set(size_t i, T t) {
    (root = find(root,i))->val = t;
    fix(root);
  }
  size_t size() {
    return subtree_size(root);
  }
  T min() {
    return rmq(root);
  }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int n,q;
  cin >> n >> q;
  splay_array<int> arr;
  for(int i = 0;i < n;i++) {
    int x;
    cin >> x;
    arr.insert(i,x);
  }
  for(int i = 0;i < q;i++) {
    int x,y,z;
    cin >> x >> y >> z;
    if(x == 0) {
      int l = y;
      int r = z;
      //[0,l - 1] [l, r - 1] [r] [r + 1]
      //[0,l - 1] [r] [l, r - 1] [r + 1]
      auto p = arr.split(r + 1);
      auto q = p.first.split(r);
      auto rr = q.first.split(l);
      rr.first.merge(move(q.second));
      rr.first.merge(move(rr.second));
      rr.first.merge(move(p.second));
      arr = move(rr.first);
    }
    if(x == 1) {
      int l = y;
      int r = z;
      auto p = arr.split(r + 1);
      auto q = p.first.split(l);
      cout << q.second.min() << endl;
      q.first.merge(move(q.second));
      q.first.merge(move(p.second));
      arr = move(q.first);
    }
    if(x == 2) {
      int pos = y;
      int val = z;
      arr.set(pos,val);
    }
  }
}



Measured memory_bytes: 14460