#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N,M; int A[1010]; ll ma=0; int mid=0; ll calc() { int x,y; ll pat=0; FOR(x,N) { set L,M,R; FOR(y,x) L.insert(A[y]); for(y=x+1;yA[x]) sc=max(A[y],*L.rbegin()); } else { if(*L.begin()max(A[x],A[y])) sc = max(sc,*M.rbegin()); if(*M.begin()A[y]) { if(*R.rbegin()>A[y]) sc=max(sc,max(A[x],*R.rbegin())); } else { if(*R.begin()>N>>M; FOR(y,M) { FOR(x,N) cin>>A[x]; ll v=calc(); if(v>ma) ma=v,mid=y; } cout<