MicroRNA Ranking

Given k permutations of n items, find a permutation where every earlier item beats the later one in at least half the rankings, choosing the lexicographically smallest such permutation.

Medium7GraphTopological sortSortingGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

Ahlaam studies computer science and is writing her master's thesis on a bioinformatics project about microRNAs, a class of molecules found in cells. She wants to find the microRNAs that are relevant to one health factor in humans.

Ahlaam has designed kk microRNA ranking algorithms. Each algorithm ranks the microRNAs from its own point of view. There are nn microRNAs numbered 11 through nn, and each algorithm prints one permutation of them. In the permutation printed by an algorithm, the first microRNA is the one that algorithm considers most relevant to the health factor, and the last one is the least relevant.

Ahlaam wants to report a consensus ranking. In a consensus ranking, if microRNA ii is placed before microRNA jj, then at least half of the algorithms must rank ii before jj. Write a program that helps Ahlaam find a consensus ranking.

Input

The input holds several test cases. The first line of each test case has two integers nn and kk separated by a space, the number of microRNAs and the number of ranking algorithms (1n10001 \le n \le 1000, 1k2001 \le k \le 200).

Each of the next kk lines holds a permutation of the numbers 11 through nn. The ii-th of those lines is the output of the ii-th ranking algorithm.

The last line of the input is 0 0. Do not process that line.

Output

For each test case, print one line holding a permutation of the numbers 11 through nn that is a consensus ranking. Separate the numbers with single spaces.

If more than one consensus ranking exists, print the lexicographically smallest one. A sequence a1,,ana_1, \dots, a_n is lexicographically smaller than a sequence b1,,bnb_1, \dots, b_n if there is a positive integer jj such that ai=bia_i = b_i for all 1ij11 \le i \le j - 1 and aj<bja_j < b_j.

If no consensus ranking exists, print No solution instead.