def calc_score(E, N): maxLeft, minLeft = calc_max_min_left(E) maxRight, minRight = calc_max_min_right(E) score = 0 for L in range(N-1): EL = E[L] for R in range(L + 1, N): if EL < E[R]: s = 0 if L: maxL = maxLeft[L - 1] if maxL > EL: s = max(E[R], maxL) if R < N - 1: minR = minRight[R + 1] if minR < E[R]: s = max(s, E[R]) else: s = 0 if L: minL = minLeft[L - 1] if minL < EL: s = EL if R < N - 1: maxR = maxRight[R + 1] if maxR > E[R]: s = max(s, EL, maxR) score += s return score def calc_max_min_left(E): maxL = 0 minL = 1000 maxLeft = [] minLeft = [] for e in E: maxL = max(maxL, e) minL = min(minL, e) maxLeft.append(maxL) minLeft.append(minL) return maxLeft, minLeft def calc_max_min_right(E): revE = E[:] revE.reverse() maxRight, minRight = calc_max_min_left(revE) maxRight.reverse() minRight.reverse() return maxRight, minRight N, M = map(int, input().split()) Es = [] for m in range(M): Es.append(list(map(int, input().split()))) scores = [calc_score(E, N) for E in Es] maxS = max(scores) print(scores.index(maxS))