/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

// Original: https://img.atcoder.jp/practice2/ac-library.zip



#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
// Sample Usages (copy-and-paste it!)

// RangeSumQuery
auto f = [](ll a, ll b) { return a+b; };
auto e = []() { return 0; };

// RangeMaximumQuery:
auto f = [](ll a, ll b) { return max(a, b); };
auto e = []() { return LLONG_MIN/2 };

// RangeMinimumQuery:
auto f = [](ll a, ll b) { return min(a, b); };
auto e = []() { return LLONG_MAX/2 };

auto seg = segtree<ll, f, e>(v);
*/

template<class S, S (*op)(S, S), S (*e)()>
struct segtree {
public:
    segtree() : segtree(0) {}

    segtree(int n) : segtree(std::vector<S>(n, e())) {}

    segtree(const std::vector<S> &v) : _n(int(v.size())) {
      log = 0;
      while((1U << log) < (unsigned int)(_n)) log++; // ceil_pow2(_n)
      size = 1 << log;
      d = std::vector<S>(2 * size, e());
      for (int i = 0; i < _n; i++) d[size + i] = v[i];
      for (int i = size - 1; i >= 1; i--) {
        update(i);
      }
    }

    void set(int p, S x) {
      assert(0 <= p && p < _n);
      p += size;
      d[p] = x;
      for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
      assert(0 <= p && p < _n);
      return d[p + size];
    }

    S prod(int l, int r) {
      assert(0 <= l && l <= r && r <= _n);
      S sml = e(), smr = e();
      l += size;
      r += size;

      while (l < r) {
        if (l & 1) sml = op(sml, d[l++]);
        if (r & 1) smr = op(d[--r], smr);
        l >>= 1;
        r >>= 1;
      }
      return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    template<bool (*f)(S)>
    int max_right(int l) {
      return max_right(l, [](S x) { return f(x); });
    }

    // return the smallest r such that f(op(a[l], ... ,a[r-1])) become false
    // f(e()) must return true
    template<class F>
    int max_right(int l, F f) {
      assert(0 <= l && l <= _n);
      assert(f(e()));
      if (l == _n) return _n;
      l += size;
      S sm = e();
      do {
        while (l % 2 == 0) l >>= 1;
        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 & -l) != l);
      return _n;
    }

    template<bool (*f)(S)>
    int min_left(int r) {
      return min_left(r, [](S x) { return f(x); });
    }

    // return the largest l such that f(op(a[l], ... ,a[r-1])) become false
    // f(e()) must return true
    template<class F>
    int min_left(int r, F f) {
      assert(0 <= r && r <= _n);
      assert(f(e()));
      if (r == 0) return 0;
      r += size;
      S sm = e();
      do {
        r--;
        while (r > 1 && (r % 2)) r >>= 1;
        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 & -r) != r);
      return 0;
    }

private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

int target;
bool g(int v) { return v < target; }

class JSegmentTree {
public:

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, q; cin >> n >> q;
      vector<int> a(n);
      for(auto& x: a) cin >> x;

      auto f = [](int a, int b) {return max(a,b); };
      auto e = [](){ return -1; };
      segtree<int, f, e> seg(a);

      while(q--) {
        int t; cin >> t;
        if (t==1) {
          int x, v; cin >> x >> v;
          seg.set(x-1, v);
        } else if (t==2) {
          int l, r; cin >> l >> r;
          cout << seg.prod(l-1, r) << '\n';
        } else if (t==3) {
          int x; cin >> x >> target;
          cout << seg.max_right(x-1, g) + 1 << '\n';
        }
      }
    }
};

signed main() {
  JSegmentTree solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 6140