import sys import re import itertools """ defs """ """ main """ N, M = map(int, input().split()) E = list ( list( map(int,input().split()) ) for _ in range(M) ) idx = 0 maxex = 0 for m in range(M): leftmins = [None]*(N) rightmins = [None]*(N) leftmaxs = [None]*(N) rightmaxs = [None]*(N) midmins = list ( [None] * (N) for _ in range(N) ) midmaxs = list ( [None] * (N) for _ in range(N) ) leftmins[0] = E[m][0] for i in range(1, N): leftmins[i] = min(leftmins[i-1],E[m][i]) rightmins[N-1] = E[m][N-1] for i in reversed(range(0,N-1)): rightmins[i] = min(rightmins[i+1],E[m][i]) leftmaxs[0] = E[m][0] for i in range(1, N): leftmaxs[i] = max(leftmaxs[i-1],E[m][i]) rightmaxs[N-1] = E[m][N-1] for i in reversed(range(0,N-1)): rightmaxs[i] = max(rightmaxs[i+1],E[m][i]) for i in range(N): midmins[i][i] = E[m][i] midmaxs[i][i] = E[m][i] for i in range(0,N): for l in range(1,N): if (i+l>=N): break midmins[i][i+l] = min(midmins[i][i+l-1],E[m][i+l]) midmaxs[i][i+l] = max(midmaxs[i][i+l-1],E[m][i+l]) ans = 0 for i in range(0, N): for j in range(i+1, N): maximam = 0 if (E[m][i] < E[m][j]): if (i==0): tmp = 0 else: tmp = leftmaxs[i-1] if (tmp > E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = N+1 else: tmp = midmins[i+1][j-1] if (tmp < E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = 0 else: tmp = midmaxs[i+1][j-1] if (tmp > E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (j+1>=N): tmp = N+1 else: tmp = rightmins[j+1] if (tmp < E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (E[m][i] > E[m][j]): if (i==0): tmp = N+1 else: tmp = leftmins[i-1] if (tmp < E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = 0 else: tmp = midmaxs[i+1][j-1] if (tmp > E[m][i]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (i+1>j-1): tmp = N+1 else: tmp = midmins[i+1][j-1] if (tmp < E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) if (j+1>=N): tmp = 0 else: tmp = rightmaxs[j+1] if (tmp > E[m][j]): maximam = max(E[m][i],E[m][j],tmp, maximam) ans += maximam expectation = ans if (idx==-1 or expectation > maxex): idx = m maxex = expectation print (idx)