#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MinMonoid {
  using T = int;
  static T op(const T& lhs, const T& rhs) { return min(lhs, rhs); }
  static constexpr T e() { return numeric_limits<T>::max(); }
};

template<class Monoid> struct RandomizedBinarySearchTree {
  using M = Monoid;
  using T = typename M::T;
  struct Node;
  using Tree = Node*;

  struct Node {
    T a, val;
    Tree cl, cr;
    int n;
    Node(const T& a = M::e()) : a(a), val(a), cl(nullptr), cr(nullptr), n(1) {}
  };

  static Tree merge(Tree tl, Tree tr) {
    if (!tr) return tl;
    if (!tl) return tr;
    if (rng(0, tl->n + tr->n) < tl->n) {
      tl->cr = merge(tl->cr, tr);
      return update(tl);
    } else {
      tr->cl = merge(tl, tr->cl);
      return update(tr);
    }
  }

  static pair<Tree, Tree> split(Tree t, int i) {
    if (!t) return {nullptr, nullptr};
    int nl = t->cl ? t->cl->n : 0;
    if (i <= nl) {
      Tree resl;
      tie(resl, t->cl) = split(t->cl, i);
      return {resl, update(t)};
    } else {
      Tree resr;
      tie(t->cr, resr) = split(t->cr, i - nl - 1);
      return {update(t), resr};
    }
  }

  static Tree insert(Tree t, int i, const T& a) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    return merge(merge(tl, new Node(a)), tr);
  }

  static Tree erase(Tree t, int i) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    tr = split(tr, 1).second;
    return merge(tl, tr);
  }

private:
  template<class Int> static Int rng(Int a, Int b) {
    static mt19937 mt(chrono::steady_clock().now().time_since_epoch().count());
    assert(a < b);
    return uniform_int_distribution<Int>(a, b - 1)(mt);
  }

  static Tree update(Tree t) {
    t->n = (t->cl ? t->cl->n : 0) + 1 + (t->cr ? t->cr->n : 0);
    t->val = M::op(M::op(t->cl ? t->cl->val : M::e(), t->a), t->cr ? t->cr->val : M::e());
    return t;
  }
};

using RBST = RandomizedBinarySearchTree<MinMonoid>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  RBST::Tree t = nullptr;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    t = RBST::insert(t, i, a);
  }
  for (int _ = 0; _ < q; ++_) {
    int type; cin >> type;
    if (type == 0) {
      int l, r; cin >> l >> r, ++r;
      RBST::Tree tl, tm, tr;
      tie(tm, tr) = RBST::split(t, r);
      tie(tl, tm) = RBST::split(tm, l);
      RBST::Tree tml, tmr;
      tie(tml, tmr) = RBST::split(tm, r - l - 1);
      tm = RBST::merge(tmr, tml);
      t = RBST::merge(RBST::merge(tl, tm), tr);
    } else if (type == 1) {
      int l, r; cin >> l >> r, ++r;
      RBST::Tree tl, tm, tr;
      tie(tm, tr) = RBST::split(t, r);
      tie(tl, tm) = RBST::split(tm, l);
      cout << tm->val << '\n';
      t = RBST::merge(RBST::merge(tl, tm), tr);
    } else {
      int i, a; cin >> i >> a;
      t = RBST::erase(t, i);
      t = RBST::insert(t, i, a);
    }
  }
}


Measured memory_bytes: 15692