// @EXPECTED_RESULTS@: WRONG_ANSWER, TIME_LIMIT_EXCEEDED import java.io.*; import java.util.*; import java.util.stream.IntStream; public class SolutionIvan { public static void main(String[] args) throws IOException { new SolutionIvan().run(); } int n, k; List> results; List> pos; static class Value { int res; int pos; int cost; public Value(int res, int pos, int cost) { this.res = res; this.pos = pos; this.cost = cost; } } BufferedReader input; StringTokenizer tokenizer; String next() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(input.readLine()); } return tokenizer.nextToken(); } int nextInt() { try { return Integer.parseInt(next()); } catch (IOException e) { throw new RuntimeException(e); } } public void run() throws IOException { input = new BufferedReader(new InputStreamReader(System.in)); n = nextInt(); k = nextInt(); results = IntStream.range(0, k).mapToObj(i -> IntStream.range(0, n).mapToObj(j -> nextInt() - 1).toList()).toList(); pos = new ArrayList<>(k); for (int i = 0; i < k; ++i) { List p = new ArrayList<>(IntStream.range(0, n).boxed().toList()); for (int j = 0; j < n; ++j) { p.set(results.get(i).get(j), j); } pos.add(p); } List candidates = new ArrayList<>(n * n); for (int res = 0; res < n; ++res) { for (int p = 0; p < n; ++p) { int cost = 0; for (int s = 0; s < k; ++s) { cost += (p - pos.get(s).get(res)) * (p - pos.get(s).get(res)); } candidates.add(new Value(res, p, cost)); } } candidates.sort(Comparator.comparingInt(v -> v.cost)); List ans = new ArrayList<>(IntStream.range(0, n).boxed().toList()); boolean[] usedP = new boolean[n]; boolean[] usedR = new boolean[n]; Arrays.fill(usedP, false); Arrays.fill(usedR, false); for (Value v : candidates) { if (usedP[v.pos] || usedR[v.res]) { continue; } ans.set(v.pos, v.res + 1); usedP[v.pos] = true; usedR[v.res] = true; } for (int r : ans) { System.out.print(r); System.out.print(' '); } System.out.println(); } }