import std.stdio; import std.ascii; import std.range; import std.array; import std.functional; import std.algorithm; import std.conv; import std.container; import std.math; import std.numeric; import std.string; import std.random; import std.regex; import std.typecons; void main() { int N, M; scanf("%d %d\n", &N, &M); auto E = new int[][M]; foreach (i; 0 .. M) { E[i] = readln.chomp.split(" ").map!(to!int).array; } bool kadomatsu(int a, int b, int c) { if (a < b && b < c) return false; if (c < b && b < a) return false; if (a == b || b == c || c == a) return false; return true; } auto T = new RedBlackTree!(Tuple!(int, int, int))[M]; foreach (i; 0 .. M) { T[i] = new RedBlackTree!(Tuple!(int, int, int)); } for (int p = 0; p < M; p++) { const int[] X = E[p]; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = j + 1; k < N; k++) { int x = X[i], y = X[j], z = X[k]; if (kadomatsu(x, y, z)) { T[p].insert(tuple(x, y, z)); } } } } } auto Z = new int[M]; for (int x = 1; x <= N; x++) { for (int y = 1; y <= N; y++) { if (x == y) continue; foreach (p; 0 .. M) { int m = 0; for (int z = 1; z <= N; z++) { if (x == z || y == z) continue; auto r = [x, y, z]; sort(r); do { auto t = tuple(r[0], r[1], r[2]); if (t in T[p]) { m = max(m, x, y, z); } } while (nextPermutation(r)); } Z[p] += m; } } } int s = -1, index = -1; foreach (int i; 0 .. M) { if (s < Z[i]) { s = Z[i]; index = i; } } writeln(index); }