import java.util.*; public class Main { static int N; static long[] dat1; static long[] dat2; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); init(n); int m = sc.nextInt(); long[] ki = new long[m]; long ma = 0; for(int i = 0; i < m; i++) { long[] E = new long[n]; for(int j = 0; j < n; j++) { E[j] = sc.nextLong(); update(j, E[j]); } long t = 0; for(int j = 0; j < n - 1; j++) { for(int k = j + 1; k < n; k++) { long[] r = query(j, k + 1, 0, 0, N); long re = 0; if((r[1] > E[j]) && (r[1] > E[k])) { long m1 = Math.max(E[j], E[k]); if((r[0] < E[j]) && (r[0] < E[k])) { if(r[1] >= m1) { re = Math.max(re, r[1]); } else { re = Math.max(re, m1); } } else { re = Math.max(re, r[1]); } } else { if((r[0] < E[j]) && (r[0] < E[k])) re = Math.max(re, Math.max(E[j], E[k])); } if(j > 0) { long[] g = query(0, j, 0, 0, N); if(E[j] > E[k]) { if(g[0] < E[j]) re = Math.max(re, E[j]); } else { if(g[1] > E[j]) re = Math.max(re, Math.max(g[1], E[k])); } } if(k < n - 1) { long[] h = query(k + 1, N, 0, 0, N); if(E[j] > E[k]) { if(h[1] > E[k]) re = Math.max(re, Math.max(h[1], E[j])); } else { if(h[0] < E[k]) re = Math.max(re, E[k]); } } t += re; } } ki[i] = t; ma = Math.max(ma, t); } for(int i = 0; i < m; i++) { if(ki[i] == ma) { System.out.println(i); break; } } } public static void init(int n_) { int n = 1; while(n < n_) { n *= 2; } N = n; dat1 = new long[2 * N - 1]; dat2 = new long[2 * N - 1]; for(int i = 0; i < dat1.length; i++) { dat1[i] = 100000; dat2[i] = (-1) * 100000; } } public static void update(int k, long x) { int a = k + N - 1; dat1[a] = x; dat2[a] = x; while(a > 0) { a = (a - 1) / 2; dat1[a] = Math.min(dat1[2 * a + 1], dat1[2 * a + 2]); dat2[a] = Math.max(dat2[2 * a + 1], dat2[2 * a + 2]); } } public static long[] query(int a, int b, int k, int l, int r) { long[] ret = new long[2]; if((r <= a) || (l >= b)) { ret[0] = 100000; ret[1] = (-1) * 100000; return ret; } if((a <= l) && (r <= b)) { ret[0] = dat1[k]; ret[1] = dat2[k]; return ret; } else { long[] retl = query(a, b, 2 * k + 1, l, (l + r) / 2); long[] retr = query(a, b, 2 * k + 2, (l + r) / 2, r); ret[0] = Math.min(retl[0], retr[0]); ret[1] = Math.max(retl[1], retr[1]); return ret; } } }