#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(double *x){scanf("%lf",x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template void reader(T *x, S *y){reader(x);reader(y);} template void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(double x, char c){printf("%.15f",x);mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template void writerLn(T x){writer(x,'\n');} template void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} char memarr[17000000]; void *mem = memarr; #define MD 1000000007 int N, M; int A[3][888]; int g[3]; int mx[888][888], mn[888][888]; int main(){ int i, j, k; int x, y, z, t; reader(&N,&M); rep(i,M) rep(j,N) reader(A[i]+j), A[i][j]--; rep(k,M){ rep(i,N){ mn[i][i] = mx[i][i] = A[k][i]; REP(j,i+1,N){ mn[i][j] = min(mn[i][j-1], A[k][j]); mx[i][j] = max(mx[i][j-1], A[k][j]); } } rep(x,N) REP(y,x+1,N){ z = -1; if(y!=x+1){ t = mx[x+1][y-1]; if(t > max(A[k][x],A[k][y])) z = max(z,t); t = mn[x+1][y-1]; if(t < min(A[k][x],A[k][y])) z = max(z,max(A[k][x],A[k][y])); } if(A[k][x] < A[k][y]){ if(x-1>=0){ t = mx[0][x-1]; if(t > A[k][x]) z = max(z,max(A[k][y],t)); } if(y+1=0){ t = mn[0][x-1]; if(t < A[k][x]) z = max(z,A[k][x]); } if(y+1 A[k][y]) z = max(z,max(A[k][x],t)); } } g[k] += z+1; } } rep(i,M){ rep(j,M) if(g[i] < g[j]) break; if(j==M){ writerLn(i); return 0; } } return 0; }