using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        int N = Reader.Int(), Q = Reader.Int();
        var set = new Set();
        for (int i = 0; i < N; i++)
            set.Insert(i, Reader.Int());
        foreach (var q in Reader.IntTable(Q))
            if (q[0] == 0)
            {
                // b1, b2 -> b2, b1
                int L = q[1], R = q[2] + 1;
                Set.Node a, b, b1, b2, c, t;
                Set.Split(set.Root, R, out t, out c);
                Set.Split(t, L, out a, out b);
                Set.Split(b, R - L - 1, out b1, out b2);
                set.Root = Set.Merge(a, b2);
                set.Root = Set.Merge(set.Root, b1);
                set.Root = Set.Merge(set.Root, c);
            }
            else if (q[0] == 1)
                Console.WriteLine(set.Min(q[1], q[2] + 1));
            else
            {
                set.RemoveAt(q[1]);
                set.Insert(q[1], q[2]);
            }
        Console.Out.Flush();
        Console.ReadLine();
    }



    public class Set
    {
        public class Node
        {
            static readonly Random random = new Random(0);
            public Node L, R;
            public int Count;
            public int Val;
            public int Min;
            //public int Max;
            //public int Sum;
            public readonly int Priority;

            public Node(int val)
            {
                Val = val; Count = 1; Priority = random.Next();
                Min = val;
                //Max = val;
                //Sum = val;
            }
            public override string ToString()
            {
                return Val + " L:" + (L == null ? "null" : L.Val + "") + " R:" + (R == null ? "null" : R.Val + "");
            }
        }

        public Node Root;
        public int Count { get { return Size(Root); } }
        static int Size(Node n) { return n == null ? 0 : n.Count; }
        static int GetMin(Node n) { return n == null ? int.MaxValue : n.Min; }
        //static int GetMax(Node n) { return n == null ? int.MinValue : n.Min; }

        static Node Update(Node n)
        {
            n.Count = 1 + (n.L == null ? 0 : n.L.Count) + (n.R == null ? 0 : n.R.Count);
            n.Min = Math.Min(n.Val, Math.Min(GetMin(n.L), GetMin(n.R)));
            //n.Max = Math.Max(n.Max, Math.Max(GetMax(n.L), GetMax(n.R)));
            //n.Sum = n.Val + (n.L == null ? 0 : n.L.Sum) + (n.R == null ? 0 : n.R.Sum);
            return n;
        }

        public int RangeQuery(int L, int R, Func<Node, int> f)
        {
            Debug.Assert(L >= 0 && L < Count && R > L && R <= Count);
            Node a, b, c, d;
            Split(Root, L, out a, out b);
            Split(b, R - L, out c, out d);
            int res = f(c);
            Root = Merge(c, d);
            Root = Merge(a, Root);
            return res;
        }

        public int Min(int L, int R) { return RangeQuery(L, R, n => n.Min); }
        //public int Max(int L, int R) { return RangeQuery(L, R, n => n.Max); }
        //public int Sum(int L, int R) { return RangeQuery(L, R, n => n.Sum); }

        public int IndexOf(int val)
        {
            int index = 0;
            var node = Root;
            while (node != null)
            {
                if (val == node.Val) return index + Size(node.L);
                if (val < node.Val) node = node.L;
                else { index += Size(node.L) + 1; node = node.R; }
            }
            return ~index;
        }

        public bool Add(int val)
        {
            int index = IndexOf(val);
            if (index >= 0) return false;
            Root = Insert(Root, new Node(val), ~index);
            return true;
        }

        public bool Remove(int val)
        {
            int index = IndexOf(val);
            if (index < 0) return false;
            RemoveAt(index);
            return true;
        }

        public int KthSmallest(int index)
        {
            Debug.Assert(index >= 0 && index < Size(Root));
            var node = Root;
            while (index != Size(node.L))
                if (index < Size(node.L)) node = node.L;
                else { index -= Size(node.L) + 1; node = node.R; }
            return node.Val;
        }

        public static Node Merge(Node L, Node R)
        {
            if (L == null) return R;
            if (R == null) return L;
            if (L.Priority > R.Priority)
            {
                L.R = Merge(L.R, R);
                return Update(L);
            }
            R.L = Merge(L, R.L);
            return Update(R);
        }

        public static void Split(Node n, int index, out Node L, out Node R)
        {
            if (n == null) { L = R = null; return; }
            Node a, b;
            if (index <= Size(n.L))
            {
                Split(n.L, index, out a, out b);
                n.L = b;
                L = a;
                R = Update(n);
            }
            else
            {
                Split(n.R, index - Size(n.L) - 1, out a, out b);
                n.R = a;
                L = Update(n);
                R = b;
            }
        }

        public void Insert(int index, int val) { Root = Insert(Root, new Node(val), index); }

        public Node Insert(Node node, Node newNode, int index)
        {
            if (node == null || index == Size(node.L) || newNode.Priority > node.Priority)
            {
                Node L, R;
                Split(node, index, out L, out R);
                node = Merge(L, newNode);
                node = Merge(node, R);
            }
            else
            {
                if (index < Size(node.L))
                    node.L = Insert(node.L, newNode, index);
                else
                    node.R = Insert(node.R, newNode, index - Size(node.L) - 1);
                Update(node);
            }
            return node;
        }

        public void RemoveAt(int index) { Root = RemoveAt(Root, index); }

        Node RemoveAt(Node node, int index)
        {
            if (node == null || index == Size(node.L))
            {
                Node L1, R1, L2, R2;
                Split(node, index, out L1, out R1);
                Split(R1, 1, out L2, out R2);
                node = Merge(L1, R2);
            }
            else
            {
                if (index < Size(node.L))
                    node.L = RemoveAt(node.L, index);
                else
                    node.R = RemoveAt(node.R, index - Size(node.L) - 1);
                Update(node);
            }
            return node;
        }

    }

}

class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 40160