#include #include #include #include #include #include using namespace std; bool isKadomatu(int a, int b, int c) { if (a == b || b == c || c == a) { return false; } if (max({a, b, c}) == b || min({a, b, c}) == b) { return true; } return false; } int calc_maximum(vector &kuji, int idx_x, int idx_y) { if (idx_x > idx_y) { swap(idx_x, idx_y); } int limit = kuji.size(); int maxi = 0; for (int i = 0; i < idx_x; i++) { if (isKadomatu(kuji[i], kuji[idx_x], kuji[idx_y])) { maxi = max(maxi, max({kuji[i], kuji[idx_x], kuji[idx_y]})); } } for (int i = idx_x + 1; i < idx_y; i++) { if (isKadomatu(kuji[idx_x], kuji[i], kuji[idx_y])) { maxi = max(maxi, max({kuji[idx_x], kuji[i], kuji[idx_y]})); } } for (int i = idx_y + 1; i < limit; i++) { if (isKadomatu(kuji[idx_x], kuji[idx_y], kuji[i])) { maxi = max(maxi, max({kuji[idx_x], kuji[idx_y], kuji[i]})); } } return maxi; } int main() { int n, m; cin >> n >> m; vector> e(m, vector(n, -1)); vector> val2idx(m, vector(n, -1)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> e[i][j]; val2idx[i][e[i][j]] = j; } } vector total(m, 0); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { for (int k = 0; k < m; k++) { total[k] += calc_maximum(e[k], val2idx[k][i], val2idx[k][j]); } } } int maxi = -1; int ans = -1; for (int i = 0; i < m; i++) { if (maxi < total[i]) { maxi = total[i]; ans = i; } } cout << ans << endl; return 0; }