# 2016.2.11 def omikuji(inp): global N total = 0 kuji = map(int, inp.split()) 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: sec3min = kuji[j+1] for k in range(j+1, N): if sec3min > kuji[k]: sec3min = kuji[k] if sec3min < B: 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 = kuji[j+1] for k in range(j+1, N): if sec3max < kuji[k]: sec3max = kuji[k] 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 totalpoint print ans