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();
        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;
                Treap.Node a, b, b1, b2, c, t;
                Treap.Split(tree.Root, R, out t, out c);
                Treap.Split(t, L, out a, out b);
                Treap.Split(b, R - L - 1, out b1, out b2);
                tree.Root = Treap.Merge(a, b2);
                tree.Root = Treap.Merge(tree.Root, b1);
                tree.Root = Treap.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 class Node
        {
            public Node L, R;
            public int Count;
            public int Val;
            public int Min;
            //public int Max;
            //public int Sum;
            public readonly uint Priority;
            static readonly XorShift random = new XorShift();

            public Node(int val)
            {
                Val = val; Count = 1; Priority = random.Next();
                Min = val;
                //Max = val;
                //Sum = val;
            }
        }
        public class XorShift
        {
            uint m = 2463534242;
            public uint Next() { m = m ^ m << 13; m = m ^ m >> 17; return m = m ^ m << 5; }
        }

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

        Node GenNode(int val) { return new Node(val); }

        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        static Node Update(Node node)
        {
            node.Count = 1 + Size(node.L) + Size(node.R);
            node.Min = Math.Min(node.Val, Math.Min(node.L == null ? int.MaxValue : node.L.Min, node.R == null ? int.MaxValue : node.R.Min));
            //node.Max = Math.Max(node.Val, Math.Max(Max(node.L), Max(node.R)));
            //node.Sum = node.Val + Sum(node.L) + Sum(node.R);
            return node;
        }

        public int this[int i]
        {
            get { return Get(Root, i); }
            set { Set(Root, i, value); }
        }
        public static int Get(Node node, int index)
        {
            Debug.Assert(node != null);
            int Lsize = Size(node.L);
            if (index == Lsize) return node.Val;
            if (index < Lsize) return Get(node.L, index);
            return Get(node.R, index - Lsize - 1);
        }
        public static void Set(Node node, int index, int val)
        {
            Debug.Assert(node != null);
            int Lsize = Size(node.L);
            if (index == Lsize) node.Val = val;
            else if (index < Lsize) Set(node.L, index, val);
            else Set(node.R, index - Lsize - 1, val);
            Update(node);
        }
        public void Add(int index, int val) { Add(Root, index, val); }
        public static void Add(Node node, int index, int val)
        {
            int Lsize = Size(node.L);
            if (index == Lsize) node.Val += val;
            else if (index < Lsize) Add(node.L, index, val);
            else Add(node.R, index - Lsize - 1, val);
            Update(node);
        }

        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);
            }
            else
            {
                R.L = Merge(L, R.L);
                return Update(R);
            }
        }

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

        public void Insert(int index, int val) { Root = Insert(Root, GenNode(val), index); }
        public static Node Insert(Node node, Node newNode, int index)
        {
            if (node == null) return newNode;
            if (newNode.Priority > node.Priority)
            {
                Node L, R;
                Split(node, index, out L, out R);
                return Merge(Merge(L, newNode), 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);
                return Update(node);
            }
        }

        public void RemoveAt(int index) { Root = RemoveAt(Root, index); }
        public static Node RemoveAt(Node node, int index)
        {
            int Lsize = Size(node.L);
            if (index == Lsize)
                return Merge(node.L, node.R);
            if (index < Lsize)
                node.L = RemoveAt(node.L, index);
            else
                node.R = RemoveAt(node.R, index - Lsize - 1);
            return Update(node);
        }

        int RangeQuery(Node node, int L, int R, int init, Func<Node, int> nF, Func<int, int, int> F)
        {
            if (node == null || L >= R) return init;
            if (L == 0 && R == node.Count) return nF(node);
            int res = init;
            int Lsize = Size(node.L);
            if (Lsize >= L && Lsize < R)
                res = node.Val;
            if (L < Lsize)
                res = F(res, RangeQuery(node.L, L, Math.Min(R, Lsize), init, nF, F));
            if (R - Lsize - 1 > 0)
                res = F(res, RangeQuery(node.R, Math.Max(0, L - Lsize - 1), R - Lsize - 1, init, nF, F));
            return res;
        }
        public int Min(int L, int R) { return RangeQuery(Root, L, R, int.MaxValue, n => n.Min, Math.Min); }
        //public int Max(int L, int R) { return RangeQuery(Root, L, R, int.MinValue, n => n.Max, Math.Max); }
        //public int 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: 42676