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


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

namespace RandomizedBinarySearchTree {
  using T = int;
  struct Node;
  using Tree = Node*;

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

  static Tree update(Tree t) {
    t->n = (t->cl ? t->cl->n : 0) + 1 + (t->cr ? t->cr->n : 0);
    t->val = min<T>({t->cl ? t->cl->val : inf, t->a, t->cr ? t->cr->val : inf});
    return t;
  }

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

using namespace RandomizedBinarySearchTree;

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