/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.8.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;

// import dcomp.tree;

int main() {
    Scanner sc = new Scanner(stdin);
    int n, q;
    sc.read(n, q);
    int[] a = new int[n];
    foreach (i; 0..n) {
        sc.read(a[i]);
    }
    auto tr = SimpleTree!(int, min, int.max)(a);
    foreach (i; 0..q) {
//        writeln(tr);
//        tr.pr();
        int x, y, z;
        sc.read(x, y, z);
        if (x == 0) {
            //shift
            auto tr4 = tr.split(z+1);
            auto tr3 = tr.split(z);
            auto tr2 = tr.split(y);
            tr.merge(tr3).merge(tr2).merge(tr4);
        } else if (x == 1) {
            //min
            writeln(tr[y..z+1].sum());
        } else {
            //assign
            tr[y] = z;
        }
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

 
static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }
     
}

import core.bitop : popcnt;
static if (!__traits(compiles, popcnt(ulong.max))) {
    public import core.bitop : popcnt;
    int popcnt(ulong v) {
        return popcnt(cast(uint)(v)) + popcnt(cast(uint)(v>>32));
    }
}

bool poppar(ulong v) {
    v^=v>>1; v^=v>>2;
    v&=0x1111111111111111UL;
    v*=0x1111111111111111UL;
    return ((v>>60) & 1) != 0;
}


 
T[N] fixed(T, size_t N)(T[N] a) {return a;}

 
 

/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/tree.d */
// module dcomp.tree;

import std.traits;

struct SimpleTree(T, alias _op, T _e) {
    import std.functional : binaryFun;
    alias op = binaryFun!_op;
    static immutable T e = _e;
    
    alias NP = Node*;
     
    static struct Node {
        NP[2] ch;
        uint length;
        T v;
        this(in T v) {
            length = 1;
            this.v = v;
        }
        this(NP l, NP r) {
            ch = [l, r];
            update();
        }
        void update() {
            length = ch[0].length + ch[1].length;
            v = op(ch[0].v, ch[1].v);
        }
        NP rot(uint type) {
             
            auto m = ch[type];
            ch[type] = m.ch[1-type];
            m.ch[1-type] = &this;
            update(); m.update();
            return m;
        }
        NP bal() {
            foreach (f; 0..2) {
                if (ch[f].length*2 > ch[1-f].length*5) {
                    if (ch[f].ch[1-f].length*2 > ch[1-f].length*5 ||
                        ch[f].ch[f].length*5 < (ch[f].ch[1-f].length+ch[1-f].length)*2) {
                        ch[f] = ch[f].rot(1-f);
                        update();
                    }
                    return rot(f);
                }
            }
            return &this;
        }
        NP insert(uint k, in T v) {
            assert(0 <= k && k <= length);
            if (length == 1) {
                if (k == 0) {
                    return new Node(new Node(v), &this);
                } else {
                    return new Node(&this, new Node(v));
                }
            }
            if (k < ch[0].length) {
                ch[0] = ch[0].insert(k, v);
            } else {
                ch[1] = ch[1].insert(k-ch[0].length, v);
            }
            update();
            return bal();
        }
        NP removeAt(uint k) {
            assert(0 <= k && k < length);
            if (length == 1) {
                return null;
            }
            if (k < ch[0].length) {
                ch[0] = ch[0].removeAt(k);
                if (ch[0] is null) return ch[1];
            } else {
                ch[1] = ch[1].removeAt(k-ch[0].length);
                if (ch[1] is null) return ch[0];
            }
            update();
            return bal();
        }
        const(T) at(uint k) const {
            assert(0 <= k && k < length);
            if (length == 1) return v;
            if (k < ch[0].length) return ch[0].at(k);
            return ch[1].at(k-ch[0].length);
        }
        void atAssign(uint k, in T x) {
            assert(0 <= k && k < length);
            if (length == 1) {
                v = x;
                return;
            }
            if (k < ch[0].length) ch[0].atAssign(k, x);
            else ch[1].atAssign(k-ch[0].length, x);
            update();
        }        
        const(T) sum(int a, int b) const {
            if (b <= 0 || length.to!int <= a) return e;
            if (a <= 0 && length.to!int <= b) return v;
            return op(ch[0].sum(a, b), ch[1].sum(a - ch[0].length, b - ch[0].length));
        }
        void check() {
            if (length == 1) return;
            assert(length == ch[0].length + ch[1].length);
            ch[0].check();
            ch[1].check();
            assert(ch[0].length*5 >= ch[1].length*2);
            assert(ch[1].length*5 >= ch[0].length*2);
        }
        void pr() {
            import std.stdio;
            if (length == 1) {
                writef("(%d)", v);
                return;
            }
            write("(");
            ch[0].pr();
            write(v);
            ch[1].pr();
            write(")");
        }
    }
    static NP merge(NP l, NP r, NP buf = null) {
        if (!l) return r;
        if (!r) return l;
        if (l.length*2 > r.length*5) {
            l.ch[1] = merge(l.ch[1], r, buf);
            l.update();
            return l.bal();
        } else if (l.length*5 < r.length*2) {
            r.ch[0] = merge(l, r.ch[0], buf);
            r.update();
            return r.bal();
        }
        if (buf == null) buf = new Node();
        buf.ch = [l, r];
        buf.update();
        return buf;
    }
    static NP[2] split(NP n, uint k) {
        if (!n) return [null, null];
        if (n.length == 1) {
            if (k == 0) return [null, n];
            else return [n, null];
        }
        NP[2] p;
        if (k < n.ch[0].length) {
            p = split(n.ch[0], k);
            p[1] = merge(p[1], n.ch[1], n);
        } else {
            p = split(n.ch[1], k - n.ch[0].length);
            p[0] = merge(n.ch[0], p[0], n);
        }
        return p;
    }
    import std.conv : to;
    Node* tr;
    this(T v) { tr = new Node(v); }
    this(Node* tr) { this.tr = tr; }
    this(in T[] v) {
        if (v.length == 0) return;
        if (v.length == 1) {
            tr = new Node(v[0]);
            return;
        }
        auto ltr = SimpleTree(v[0..$/2]);
        auto rtr = SimpleTree(v[$/2..$]);
        this = ltr.merge(rtr);
    }
    @property size_t length() const { return (!tr ? 0 : tr.length); }
    alias opDollar = length;
    
    void insert(size_t k, in T v) {
        assert(0 <= k && k <= length);
        if (tr is null) {
            tr = new Node(v);
            return;
        }
        tr = tr.insert(k.to!int, v);
    }
    void removeAt(size_t k) {
        assert(0 <= k && k < length);
        tr = tr.removeAt(k.to!int);
    }
    SimpleTree trim(size_t a, size_t b) {
        auto v = split(tr, b.to!uint);
        auto u = split(v[0], a.to!uint);
        tr = merge(u[0], v[1]);
        return SimpleTree(u[1]);
    }
    SimpleTree split(size_t k) {
        auto u = split(tr, k.to!uint);
        tr = u[0];
        return SimpleTree(u[1]);
    }
    ref SimpleTree merge(SimpleTree r) {
        tr = merge(tr, r.tr);
        return this;
    }
    const(T) opIndex(size_t k) {
        assert(0 <= k && k < length);
        return tr.at(k.to!int);
    }
    void opIndexAssign(in T x, size_t k) {
        return tr.atAssign(k.to!int, x);
    }
    struct Range {
        SimpleTree* eng;
        size_t start, end;
        @property T sum() {
            return eng.tr.sum(start.to!uint, end.to!uint);
        }
    }
    size_t[2] opSlice(size_t dim)(size_t start, size_t end) {
        assert(0 <= start && start <= end && end <= length());
        return [start, end];
    }
    Range opIndex(size_t[2] rng) {
        return Range(&this, rng[0].to!uint, rng[1].to!uint);
    }
    string toString() {
         
        import std.range : iota;
        import std.algorithm : map;
        import std.conv : to;
        string s;
        s ~= "Tree(";
        s ~= iota(length).map!(i => this[i]).to!string;
        s ~= ")";
        return s;
    }
    void check() {
        if (tr) tr.check();
    }
    void pr() {
        if (tr) tr.pr();
    }
}

import std.traits : isInstanceOf;

ptrdiff_t binSearchLeft(alias pred, T)(T t, ptrdiff_t _a, ptrdiff_t _b)
if(isInstanceOf!(SimpleTree, T)) {
    import std.conv : to;
    import std.traits : Unqual;
    int a = _a.to!int, b = _b.to!int;
    Unqual!(typeof(T.e)) x = T.e;
    if (pred(x)) return a-1;
    if (t.tr is null) return 0;
    
    alias op = T.op;
    int pos = a;
    void f(T.Node* n, int a, int b, int offset) {
        if (b <= offset || offset + n.length <= a) return;
        if (a <= offset && offset + n.length <= b && !pred(op(x, n.v))) {
            x = op(x, n.v);
            pos = offset + n.length;
            return;
        }
        if (n.length == 1) return;
        f(n.ch[0], a, b, offset);
        if (pos >= offset + n.ch[0].length) {
            f(n.ch[1], a, b, offset + n.ch[0].length);
        }
    }
    f(t.tr, a, b, 0);
    return pos;
}

ptrdiff_t binSearchRight(alias pred, T)(T t, ptrdiff_t a, ptrdiff_t b)
if(isInstanceOf!(SimpleTree, T)) {
    import std.conv : to;
    import std.traits : Unqual;
    int a = _a.to!int, b = _b.to!int;
    Unqual!(typeof(T.e)) x = T.e;
    if (pred(x)) return b;
    if (t.tr is null) return 0;

    alias op = T.op;
    int pos = b-1;
    void f(T.Node* n, int a, int b, int offset) {
        if (b <= offset || offset + n.length <= a) return;
        if (a <= offset && offset + n.length <= b && !pred(opTT(n.v, x))) {
            x = opTT(n.v, x);
            pos = offset - 1;
            return;
        }
        if (n.length == 1) return;
        f(n.ch[1], a, b, offset + n.ch[0].length);
        if (pos < offset + n.ch[0].length) {
            f(n.ch[0], a, b, offset);
        }
    }
    f(t.tr, a, b, 0);
    return pos;
}

 

 
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.container.stackpayload;

 
class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                 
                 
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}


 
 

 
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */
// module dcomp.container.stackpayload;

struct StackPayload(T, size_t MIN = 4) {
    import core.exception : RangeError;
    import std.algorithm : max;
    import std.conv;
    import std.range.primitives : ElementEncodingType;
    import core.stdc.string : memcpy;

    private T* _data;
    private uint len, cap;
     
    bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    ref inout(T) opIndex(size_t i) inout { return _data[i]; }
    ref inout(T) front() inout { return _data[0]; }
    ref inout(T) back() inout { assert(len); return _data[len-1]; }
    
     
    void reserve(size_t nlen) {
        import core.memory : GC;
        if (nlen <= cap) return;
        
        void* nx = GC.malloc(nlen * T.sizeof);

        cap = nlen.to!uint;
        if (len) memcpy(nx, _data, len * T.sizeof);
        _data = cast(T*)(nx);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }
     
    void opOpAssign(string op : "~")(T item) {
        if (len == cap) {
            reserve(max(MIN, cap*2));
        }
        _data[len++] = item;
    }
     
    void insertBack(T item) {
        this ~= item;
    }
     
    void removeBack() {
        len--;
    }
     
    void clear() {
        len = 0;
    }
     
    inout(T)[] data() inout {
        return (_data) ? _data[0..len] : null;
    }

    static struct RangeT(A) {
        import std.traits : CopyTypeQualifiers;
        alias E = CopyTypeQualifiers!(A, T);
        A *p;
        size_t a, b;
        @property bool empty() const { return b <= a; }
        @property size_t length() const { return b-a; }
        @property RangeT save() { return RangeT(p, a, b); }
        @property RangeT!(const A) save() const {
            return typeof(return)(p, a, b);
        }
        alias opDollar = length;
        @property ref inout(E) front() inout { return (*p)[a]; }
        @property ref inout(E) back() inout { return (*p)[b-1]; }
        void popFront() {
            version(assert) if (empty) throw new RangeError();
            a++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            b--;
        }
        ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }
        RangeT opSlice() { return this.save; }
        RangeT opSlice(size_t i, size_t j) {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
        RangeT!(const A) opSlice() const { return this.save; }
        RangeT!(const A) opSlice(size_t i, size_t j) const {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
    }
    alias Range = RangeT!(StackPayload!T);
    alias ConstRange = RangeT!(const StackPayload!T);
    alias ImmutableRange = RangeT!(immutable StackPayload!T);
}

 

/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/

Measured memory_bytes: 26084