class SegTree
    def initialize(init_ary, lim, &block)
        n = init_ary.size
        @m = 1 << (n-1).bit_length
        @n = @m << 1

        @lim = lim
        @ary = Array.new(@n, @lim)
        @fanc = block

        init_ary.each_with_index {|e,i| @ary[@m+i] = e}
        (@m-1).downto(1) {|i| @ary[i] = @fanc.call(@ary[i*2], @ary[i*2+1])}
    end

    def set(i, x)
        i += @m
        @ary[i] = x
        i >>= 1

        while i >= 1
            @ary[i] = @fanc.call(@ary[i*2], @ary[i*2+1])
            i >>= 1
        end
    end

    def find(i, a, b)
        return @lim if @t < a || b < @s
        return @ary[i] if @s <= a && b <= @t

        m = (a + b) >> 1
        return @fanc.call(find(i*2, a, m), find(i*2+1, m+1, b))
    end

    def find_start(s, t)
        @s = s
        @t = t
        find(1, 0, @m-1)
    end

    def calc3(i, a, b)
        return @lim if @t < a || b < @s || @ary[i][0] < @v
        return @ary[i] if a == b

        m = (a + b) >> 1
        x = calc3(i*2, a, m)
        return x if x[1] != @lim[1]
        return calc3(i*2+1, m+1, b)
    end

    def calc3_start(s, t, v)
        @s = s
        @t = t
        @v = v
        calc3(1, 0, @m-1)
    end
end

n, q = gets.split.map(&:to_i)
a = gets.split.map.with_index{|e,i| [e.to_i, i]}

st = SegTree.new(a, [0, n]) {|ch1, ch2| ch1[0] > ch2[0] ? ch1 : ch2}

q.times do
    t, x, v = gets.split.map(&:to_i)
    if t == 1
        st.set(x-1, v)
    elsif t == 2
        puts st.find_start(x-1, v-1)[0]
    else
        puts st.calc3_start(x-1, n-1, v)[1] + 1
    end
end