#include using namespace std; #define INF 2000000000 int my_min(int a, int b) { if (ab) return a; else return b; } struct SegmentTree { int n; function func; int ele; vector arr; SegmentTree(int N, int (*f)(int, int), int e) { int n_ = 1; while (n_0) { k = (k-1)/2; arr[k] = func(arr[2*k+1], arr[2*k+2]); } } int query_sub(int a, int b, int k, int l, int r) { if (r<=a || b<=l) return ele; if (a<=l && r<=b) return arr[k]; else { int vl = query_sub(a, b, 2*k+1, l, (l+r)/2); int vr = query_sub(a, b, 2*k+2, (l+r)/2, r); return func(vl, vr); } } int query(int a, int b) { return query_sub(a, b, 0, 0, n); } }; int main() { int N, M; cin >> N >> M; int v_max = -1; int ans = -1; for (int m=0; m> E[i]; E[i]--; st_min.update(i, E[i]); st_max.update(i, E[i]); } int v = 0; for (int i=0; iE[j]) { if (min_1E[i]) prof = max(prof, max_2); if (min_2E[j]) prof = max({prof, E[i], max_3}); } else if (E[i]E[i]) prof = max({prof, max_1, E[j]}); if (min_2E[j]) prof = max(prof, max_2); if (min_3