class SegmentTree: def __init__(self, N, func): n_ = 1 while n_0: k = (k-1)//2 self.arr[k] = self.func(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r): #[l:r) L, R = l+self.n, r+self.n res = self.ele while L>= 1 R >>= 1 return res N, M = map(int, input().split()) v_max = -1 ans = -1 for m in range(M): E = list(map(lambda x: x-1, map(int, input().split()))) st_min = SegmentTree(N, min) st_max = SegmentTree(N, max) for i in range(N): st_min.update(i, E[i]) st_max.update(i, E[i]) v = 0 for i in range(N): for j in range(i+1, N): prof = 0 min_1 = st_min.query(0, i) max_1 = st_max.query(0, i) if E[i]>E[j] and min_1E[i]: prof = max(prof, max(max_1, E[j])) min_2 = st_min.query(i+1, j) max_2 = st_max.query(i+1, j) if min_2E[i] and max_2>E[j]: prof = max(prof, max_2) min_3 = st_min.query(j+1, N) max_3 = st_max.query(j+1, N) if E[i]min_3: prof = max(prof, E[j]) elif E[i]>E[j] and E[j]v_max: v_max = v ans = m print(ans)