#include using namespace std; typedef int ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; #define REP(i,n) for(ll i=0;i0){ i = (i-1)/2; datmin[i] = min(datmin[i*2+1],datmin[i*2+2]); datmax[i] = max(datmax[i*2+1],datmax[i*2+2]); } } int _min(int a,int b,int k,int l,int r){ if(r<=a||b<=l)return INF; if(a<=l&&r<=b)return datmin[k]; else{ int vl = _min(a,b,k*2+1,l,(l+r)/2); int vr = _min(a,b,k*2+2,(l+r)/2,r); return min(vl,vr); } } int qmin(int a,int b){ return _min(a,b,0,0,n); } int _max(int a,int b,int k,int l,int r){ if(r<=a||b<=l)return -INF; if(a<=l&&r<=b)return datmax[k]; else{ int vl = _max(a,b,k*2+1,l,(l+r)/2); int vr = _max(a,b,k*2+2,(l+r)/2,r); return max(vl,vr); } } int qmax(int a,int b){ return _max(a,b,0,0,n); } }; int main(){ int n,m; scanf("%d%d",&n,&m); // length : n // alternatives : m // 2個選ぶ→O(n^2) ll mxval = -1; ll ans = -1; REP(x,m){ ll lot[n]; REP(i,n)scanf("%d",&(lot[i])); rmq Q; Q.init(n); REP(i,n)Q.update(i,lot[i]); ll res = 0; REP(i,n)REP(j,i){ // ~~~ j ~~~~ i ~~~~ ll left = lot[j]; ll right = lot[i]; ll mx = 0; // cout<<"i:"<left) mx = max(mx,max(a,right)); // ↓(↑)↓ int b = Q.qmax(j+1,i); if(b>right) mx = max(mx,b); // ↑(↓)↑ int c = Q.qmin(j+1,i); if(cleft) mx = max(mx,b); // ↑(↓)↑ int c = Q.qmin(j+1,i); if(cright) mx = max(mx,max(d,left)); } res += mx; } if(res > mxval){ mxval = res; ans = x; } } cout << ans << endl; return 0; }