import sys def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 tickets = [] for _ in range(M): E = list(map(int, input[ptr:ptr+N])) ptr += N tickets.append(E) best_idx = 0 best_exp = -1.0 for idx, E in enumerate(tickets): max_prize = [[0]*(N+1) for _ in range(N+1)] # 1-based # Iterate all triplets i < j < k for i in range(N): a = E[i] for j in range(i+1, N): b = E[j] for k in range(j+1, N): c = E[k] max_val = max(a, b, c) min_val = min(a, b, c) mid_val = a + b + c - max_val - min_val if mid_val == a or mid_val == c: # Update pairs (a, b), (a, c), (b, c) pairs = [(a, b), (a, c), (b, c)] for x, y in pairs: if x == y: continue if x > y: x, y = y, x if max_prize[x][y] < max_val: max_prize[x][y] = max_val # Compute expected value total = 0 count = 0 for x in range(1, N+1): for y in range(x+1, N+1): total += max_prize[x][y] count += 1 expected = total / count if count != 0 else 0.0 if expected > best_exp or (expected == best_exp and idx < best_idx): best_exp = expected best_idx = idx print(best_idx) if __name__ == "__main__": main()