using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
//using System.Numerics;
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 A = Reader.IntArray(N);
        var tree = new Treap(N);
        for (int i = 0; i < N; i++) tree.Insert(i, A[i]);

        foreach (var q in Reader.IntTable(Q))
            if (q[0] == 0)
            {
                // b1, b2 -> b2, b1
                int L = q[1], R = q[2] + 1;
                int a, b, b1, b2, c, t;
                tree.Split(tree.Root, R, out t, out c);
                tree.Split(t, L, out a, out b);
                tree.Split(b, R - L - 1, out b1, out b2);
                tree.Root = tree.Merge(a, b2);
                tree.Root = tree.Merge(tree.Root, b1);
                tree.Root = tree.Merge(tree.Root, c);
            }
            else if (q[0] == 1)
                Console.WriteLine(tree.Min(q[1], q[2] + 1));
            else
                tree[q[1]] = q[2];
        Console.Out.Flush();
        Console.ReadLine();

    }

    public class Treap
    {
        public struct Node
        {
            public int L, R;
            public int Count;
            public long Val;
            public long Min;
            //public long Max;
            //public long Sum;
            public readonly uint Priority;
            static readonly XorShift random = new XorShift();

            public Node(long val, uint priority = uint.MaxValue)
            {
                L = R = None; Val = val; Count = 1;
                Min = val;
                //Max = val;
                //Sum = val;
                Priority = (priority == uint.MaxValue) ? random.Next() : priority;
            }
        }
        public class XorShift
        {
            uint m = 2463534242;
            public uint Next() { m = m ^ m << 13; m = m ^ m >> 17; return m = m ^ m << 5; }
        }

        static readonly int None = 0;
        int nodesIndex = 1;
        public Node[] nodes;
        public int Root;
        public int Count { get { return nodes[Root].Count; } }
        public Treap(int size) { Init(size); }

        private void Init(int size)
        {
            nodes = new Node[size + 1];
            nodes[None].Min = long.MaxValue;
            //nodes[None].Max = long.MinValue;
        }
        int GenNode(long val, uint priority = uint.MaxValue)
        {
            int i = nodesIndex++;
            nodes[i] = new Node(val, priority);
            return i;
        }

        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        int Update(int i)
        {
            nodes[i].Count = nodes[nodes[i].L].Count + nodes[nodes[i].R].Count + 1;
            nodes[i].Min = Math.Min(nodes[i].Val, Math.Min(nodes[nodes[i].L].Min, nodes[nodes[i].R].Min));
            //nodes[i].Max = Math.Max(nodes[i].Val, Math.Max(nodes[nodes[i].L].Max, nodes[nodes[i].R].Max));
            return i;
        }

        int[] setTmp = new int[128];
        public long this[int index]
        {
            get
            {
                Debug.Assert(index >= 0 && index < nodes[Root].Count);
                int i = Root;
                while (index != nodes[nodes[i].L].Count)
                    if (index < nodes[nodes[i].L].Count) i = nodes[i].L;
                    else { index -= nodes[nodes[i].L].Count + 1; i = nodes[i].R; }
                return nodes[i].Val;
            }
            set
            {
                //if (index < nodes[Root].Count) RemoveAt(index);
                //Insert(index, value);

                int num = 0;
                int i = Root, Lsize;
                while ((Lsize = nodes[nodes[i].L].Count) != index)
                    if (index < Lsize) { setTmp[num++] = i; i = nodes[i].L; }
                    else { setTmp[num++] = ~i; index -= Lsize + 1; i = nodes[i].R; }
                nodes[i].Val = value;
                Update(i);
                while (--num >= 0)
                {
                    int v = setTmp[num];
                    if (v >= 0) nodes[v].L = i;
                    else { v = ~v; nodes[v].R = i; }
                    Update(v);
                    i = v;
                }
            }
        }

        public int Merge(int L, int R)
        {
            if (L == None) return R;
            if (R == None) return L;
            if (nodes[L].Priority > nodes[R].Priority)
            {
                nodes[L].R = Merge(nodes[L].R, R);
                return Update(L);
            }
            else
            {
                nodes[R].L = Merge(L, nodes[R].L);
                return Update(R);
            }
        }

        public void Split(int i, int index, out int L, out int R)
        {
            if (i == None) { L = R = None; return; }

            if (index == nodes[nodes[i].L].Count)
            {
                L = nodes[i].L;
                R = i;
                nodes[i].L = None;
                Update(i);
                return;
            }
            int a, b;
            if (index < nodes[nodes[i].L].Count)
            {
                Split(nodes[i].L, index, out a, out b);
                nodes[i].L = b;
                L = a;
                R = Update(i);
            }
            else
            {
                Split(nodes[i].R, index - nodes[nodes[i].L].Count - 1, out a, out b);
                nodes[i].R = a;
                L = Update(i);
                R = b;
            }
        }

        public void Insert(int index, long val) { Root = Insert(Root, GenNode(val), index); }
        public int Insert(int i, int newNodeIndex, int index)
        {
            if (i == None) return newNodeIndex;
            if (nodes[newNodeIndex].Priority > nodes[i].Priority)
            {
                int L, R;
                Split(i, index, out L, out R);
                i = Merge(L, newNodeIndex);
                i = Merge(i, R);
            }
            else
            {
                if (index <= nodes[nodes[i].L].Count)
                    nodes[i].L = Insert(nodes[i].L, newNodeIndex, index);
                else
                    nodes[i].R = Insert(nodes[i].R, newNodeIndex, index - nodes[nodes[i].L].Count - 1);
                Update(i);
            }
            return i;
        }


        public void RemoveAt(int index) { Root = RemoveAt(Root, index); }
        int RemoveAt(int i, int index)
        {
            if (index == nodes[nodes[i].L].Count)
                return Merge(nodes[i].L, nodes[i].R);
            if (index < nodes[nodes[i].L].Count)
                nodes[i].L = RemoveAt(nodes[i].L, index);
            else
                nodes[i].R = RemoveAt(nodes[i].R, index - nodes[nodes[i].L].Count - 1);
            return Update(i);
        }


        //long RangeQuery(int i, int L, int R, long init, Func<int, long> nF, Func<long, long, long> F)
        //{
        //    if (i == None || L >= R) return init;
        //    if (L == 0 && R == nodes[i].Count) return nF(i);
        //    long res = init;
        //    int Lsize = nodes[nodes[i].L].Count;
        //    if (Lsize >= L && Lsize < R)
        //        res = nodes[i].Val;
        //    if (L < Lsize)
        //        res = F(res, RangeQuery(nodes[i].L, L, Math.Min(R, Lsize), init, nF, F));
        //    if (R - Lsize - 1 > 0)
        //        res = F(res, RangeQuery(nodes[i].R, Math.Max(0, L - Lsize - 1), R - Lsize - 1, init, nF, F));
        //    return res;
        //}
        public long Min(int L, int R)
        {
            return Min(Root, L, R);
            //return RangeQuery(Root, L, R, long.MaxValue, i => nodes[i].Min, Math.Min);
        }
        public long Min(int i, int L, int R)
        {
            if (i == None || L >= R) return long.MaxValue;
            if (L == 0 && R == nodes[i].Count) return nodes[i].Min;
            long res = long.MaxValue;
            int Lsize = nodes[nodes[i].L].Count;
            if (Lsize >= L && Lsize < R)
                res = nodes[i].Val;
            if (L < Lsize)
                res = Math.Min(res, Min(nodes[i].L, L, Math.Min(R, Lsize)));
            if (R - Lsize - 1 > 0)
                res = Math.Min(res, Min(nodes[i].R, Math.Max(0, L - Lsize - 1), R - Lsize - 1));
            return res;

        }

        //public long Max(int L, int R) { return RangeQuery(Root, L, R, long.MinValue, n => n.Max, Math.Max); }
        //public long Sum(int L, int R) { return RangeQuery(Root, L, R, 0, n => n.Sum, (a, b) => a + b); }

    }

}

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