import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

class SegTree<Monoid>(val n: Int, val op: (Monoid, Monoid) -> Monoid, val e: Monoid){
    var d: MutableList<Monoid>
    private var size = 1
    private var log = 0

    init {
        while (size < n) {
            size *= 2
            log++
        }
        d = MutableList(2 * size) { e }
    }

    operator fun set(i: Int, x: Monoid) {
        if (i !in 0 until n) {
            throw Exception()
        }
        val p = i + size
        d[p] = x
        for (i in 1..log) {
            update(p shr i)
        }
    }

    operator fun get(i: Int): Monoid {
        if (i !in 0 until n) {
            throw Exception()
        }
        return d[i + size]
    }

    fun prod(l: Int, r: Int): Monoid {
        if (l !in 0..r || r !in l..n) {
            throw Exception()
        }
        var sml = e
        var smr = e
        var l = l + size
        var r = r + size
        while (l < r) {
            if (l and 1 != 0) sml = op(sml, d[l++])
            if (r and 1 != 0) smr = op(d[--r], smr)
            l /= 2
            r /= 2
        }
        return op(sml, smr)
    }

    fun allProd(): Monoid {
        return d[1]
    }

    fun maxRight(l: Int, f: (Monoid) -> Boolean): Int {
        if (l !in 0..n || !f(e)) {
            throw Exception()
        }
        if (l == n) return n
        var l = l + size
        var sm = e
        do {
            while (l % 2 == 0) l /= 2
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = 2 * l
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l])
                        l++
                    }
                }
                return l - size
            }
            sm = op(sm, d[l])
            l++
        } while ((l and -l) != l)
        return n
    }

    fun minLeft(r: Int, f: (Monoid) -> Boolean): Int {
        if (r !in 0..n || !f(e)) {
            throw Exception()
        }
        if (r == 0) return 0
        var r = r + size
        var sm = e
        do {
            r--
            while (r > 1 && r % 2 != 0) r /= 2
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = 2 * r + 1
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm)
                        r--
                    }
                }
                return r + 1 - size
            }
            sm = op(d[r], sm)
        } while ((r and -r) != r)
        return 0
    }

    private fun update(k: Int) {
        d[k] = op(d[2 * k], d[2 * k + 1])
    }
}

fun op(a: Int, b: Int): Int {
    return maxOf(a, b)
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val q = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val segtree = SegTree(n, ::op, -1)
    //val segtree = SegTree(n, { x, y -> maxOf(x, y) }, -1)
    for (i in 0 until n) {
        segtree[i] = a[i]
    }
    for (i in 0 until q) {
        val t = sc.nextInt()
        if (t == 1) {
            val x = sc.nextInt() - 1
            val v = sc.nextInt()
            segtree[x] = v
        } else if (t == 2) {
            val l = sc.nextInt() - 1
            val r = sc.nextInt()
            println(segtree.prod(l, r))
        } else if (t == 3) {
            val p = sc.nextInt() - 1
            val target = sc.nextInt()
            println(segtree.maxRight(p) { v -> v < target } + 1)
        }
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 80652