package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	aa := make([]SInterface, n)
	for i := 0; i < n; i++ {
		aa[i] = &S{a: getNextInt(scanner)}
	}
	seg := NewSegTreeWithData(aa, E)
	for q > 0 {
		q--
		t := getNextInt(scanner)
		switch t {
		case 1:
			x := getNextInt(scanner) - 1
			v := getNextInt(scanner)
			seg.Set(x, &S{a: v})
		case 2:
			l := getNextInt(scanner) - 1
			r := getNextInt(scanner)
			fmt.Fprintln(writer, seg.Prod(l, r).(*S).a)
		case 3:
			x := getNextInt(scanner) - 1
			v := getNextInt(scanner)
			fmt.Fprintln(writer, seg.MaxRight(x, func(a SInterface) bool {
				aa := a.(*S).a
				return v > aa
			})+1)
		}
	}
}

type S struct {
	a int
}

func (s *S) Op(l, r SInterface) SInterface {
	ll, rr := l.(*S), r.(*S)
	if ll.a > rr.a {
		s.a = ll.a
	} else {
		s.a = rr.a
	}
	return s
}
func E() SInterface {
	return &S{a: 0}
}

// SInterface Type S interface
type SInterface interface {
	Op(SInterface, SInterface) SInterface
}

// SegTree is the data structure for monoids
type SegTree struct {
	n, size, log int
	d            []SInterface
	e            func() SInterface
}

// NewSegTree Constructor
func NewSegTree(n int, e func() SInterface) *SegTree {
	a := make([]SInterface, n)
	for i := 0; i < n; i++ {
		a[i] = e()
	}
	return NewSegTreeWithData(a, e)
}

// NewSegTreeWithData Constructor
func NewSegTreeWithData(a []SInterface, e func() SInterface) *SegTree {
	n := len(a)
	log := 0
	for i := n; i > 0; i >>= 1 {
		log++
	}
	size := 1 << log
	d := make([]SInterface, size<<1)
	for i := 0; i < size<<1; i++ {
		d[i] = e()
	}
	for i := 0; i < n; i++ {
		d[i+size] = a[i]
	}
	s := SegTree{d: d, e: e, n: n, size: size, log: log}
	for i := size - 1; i > 0; i-- {
		s.update(i)
	}
	return &s
}

// Set assigns x to a[p]
func (s *SegTree) Set(p int, x SInterface) {
	p += s.size
	s.d[p] = x
	for i := 1; i <= s.log; i++ {
		s.update(p >> i)
	}
}

// Get returns a[p]
func (s *SegTree) Get(p int) SInterface {
	return s.d[p+s.size]
}

// Prod returns op(a[l], ..., a[r - 1]), assuming the properties of the monoid. It returns e() if l = r.
func (s *SegTree) Prod(l, r int) SInterface {
	sml := s.e()
	smr := s.e()
	l += s.size
	r += s.size
	for l < r {
		if l&1 == 1 {
			sml.Op(sml, s.d[l])
			l++
		}
		if r&1 == 1 {
			r--
			smr.Op(s.d[r], smr)
		}
		l >>= 1
		r >>= 1
	}
	return sml.Op(sml, smr)
}

// AllProd returns op(a[0], ..., a[n - 1]), assuming the properties of the monoid. It returns e() if n = 0.
func (s *SegTree) AllProd() SInterface {
	return s.d[1]
}

// MaxRight returns an index r that satisfies both of the following.
// r = l or f(op(a[l], a[l + 1], ..., a[r - 1])) = true
// r = n or f(op(a[l], a[l + 1], ..., a[r])) = false
func (s *SegTree) MaxRight(l int, f func(x SInterface) bool) int {
	if l == s.n {
		return s.n
	}
	l += s.size
	sm := s.e()
	t := s.e()
	for {
		for l&1 == 0 {
			l >>= 1
		}
		if !f(t.Op(sm, s.d[l])) {
			for l < s.size {
				l <<= 1
				if f(t.Op(sm, s.d[l])) {
					sm, t = t, sm
					l++
				}
			}
			return l - s.size
		}
		sm.Op(sm, s.d[l])
		l++
		if l&-l == l {
			break
		}
	}
	return s.n
}

// MinLeft returns an index l that satisfies both of the following.
// l = r or f(op(a[l], a[l + 1], ..., a[r - 1])) = true
// l = 0 or f(op(a[l - 1], a[l + 1], ..., a[r - 1])) = false
func (s *SegTree) MinLeft(r int, f func(x SInterface) bool) int {
	if r == 0 {
		return 0
	}
	r += s.size
	sm := s.e()
	t := s.e()
	for {
		r--
		for r > 1 && r&1 == 1 {
			r >>= 1
		}
		if !f(t.Op(sm, s.d[r])) {
			for r < s.size {
				r = r<<1 + 1
				if f(t.Op(sm, s.d[r])) {
					sm, t = t, sm
					r--
				}
			}
			return r + 1 - s.size
		}
		sm.Op(sm, s.d[r])
		if r&-r == r {
			break
		}
	}
	return 0
}
func (s *SegTree) update(k int) {
	s.d[k].Op(s.d[k<<1], s.d[k<<1+1])
}


Measured memory_bytes: 28836