# 2016.2.11 def maxgetter(inpstr): out = [] inp = inpstr[0:len(inpstr)] inp.reverse() tmp = 0 for i in range(0, len(inp)): if inp[i] > tmp: tmp = inp[i] out.append(tmp) out.reverse() return out def mingetter(inpstr): out = [] inp = inpstr[0:len(inpstr)] inp.reverse() tmp = 100000 for i in range(0, len(inp)): if inp[i] < tmp: tmp = inp[i] out.append(tmp) out.reverse() return out def omikuji(inp): global N total = 0 kuji = map(int, inp.split()) maxlist = maxgetter(kuji) minlist = mingetter(kuji) sec1max = kuji[0] sec1min = kuji[0] for i in range(0, N-1): if sec1max < kuji[i-1] and i != 0: sec1max = kuji[i-1] if sec1min > kuji[i-1] and i != 0: sec1min = kuji[i-1] A = kuji[i] sec2max = kuji[i+1] sec2min = kuji[i+1] for j in range(i+1, N): if sec2max < kuji[j-1] and j != i+1: sec2max = kuji[j-1] if sec2min > kuji[j-1] and j != i+1: sec2min = kuji[j-1] B = kuji[j] flag = 0 if A < B: if sec1max > A: flag = 1 if sec2min < A: flag = 1 if max(sec1max, sec2max) > B: flag = 2 if flag == 0 and j != N-1: if B > minlist[j+1]: flag = 1 flag2point = max(sec1max, sec2max) elif A > B: if sec1min < A: flag = 1 if sec2min < B: flag = 1 if sec2max > A: flag = 2 sec3max = 0 if j != N-1: sec3max = maxlist[j+1] if B < sec3max < A and flag != 2: flag = 1 if sec3max > A: flag = 2 flag2point = max(sec2max, sec3max) if flag == 1: total += max(A, B) elif flag == 2: total += flag2point return total NM = map(int, raw_input().split()) N = NM[0] M = NM[1] totalpoint = [0 for no in range(0, M)] for no in range(0, M): totalpoint[no] = omikuji((raw_input())) totalpointmax = 0 ans = 0 for i in range(0, M): if totalpointmax < totalpoint[i]: totalpointmax = totalpoint[i] ans = i print ans