class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @e = e
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = @e
        smr = @e
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            smr = @op.call(@d[r -= 1], smr) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end

    def max_right(l, &f)
        return @n if l == @n
        l += @size
        sm = @e

        loop do
            l >>= 1 while l[0] == 0
            if !f.call(@op.call(sm, @d[l]))
                while l < @size
                    l <<= 1
                    if f.call(@op.call(sm, @d[l]))
                        sm = @op.call(sm, @d[l])
                        l += 1
                    end
                end
                return l - @size
            end
            
            sm = @op.call(sm, @d[l])
            l += 1
            break if (l & -l) == l
        end

        return @n
    end
    
    def min_left(r, &f)
        return 0 if r == 0
        r += @size
        sm = @e

        loop do
            r -= 1
            r >>= 1 while r > 1 && r[0] == 1
            if !f.call(@op.call(@d[r], sm))
                while r < @size
                    r = 2 * r + 1
                    if f.call(@op.call(@d[r], sm))
                        sm = @op.call(@d[r], sm)
                        r -= 1
                    end
                end
                return r + 1 - @size
            end
            sm = @op.call(@d[r], sm)
            break if (r & -r) == r
        end

        return 0
    end
end

n, q = gets.split.map(&:to_i)
st = SegTree.new(gets.split.map(&:to_i), -1) {|ch1, ch2| ch1 > ch2 ? ch1 : ch2}

q.times do
    t, x, y = gets.split.map(&:to_i)
    
    if t == 1
        st.set(x-1, y)
    elsif t == 2
        puts st.prod(x-1, y)
    else
        puts st.max_right(x-1){|v| v < y} + 1
    end
end