Under construction

Still being built. Things may change

Grandpa is Famous!

Interview

Time limit1sMemory limit256 MB

Summary
Given weekly ranking lists, count how many times each player appears, then print the players with the second-highest count in ascending order.
Level

Easy3 of 10

Topics
Hash map, Sorting, Implementation, Array
Solved
No attempts yet

Problem

After seeing "the news," the whole family got excited. Everyone knew that Grandpa had been an outstanding bridge (a type of card game) player for decades, but the news that he was being entered into the Guinness Book of Records as the greatest bridge player of all time was truly astonishing!

For many years, the International Bridge Association (IBA) has recorded the weekly rankings of the most skilled players. Every time a player's name appears in a week's ranking, that player earns 1 point, and Grandpa earned the most points and was named the greatest bridge player.

Grandpa had many friends who competed with him for the bridge rankings, so he was very curious about which player (or players) came in second place.

The IBA's ranking data is now available online. Write a program that takes the weekly ranking lists as input and determines who the second-place player is.

Input

Each player is identified by an integer (a player number) from 11 to 1000010000. The input consists of several test cases.

The first line of each test case contains two integers NN and MM, meaning that for NN (2≤N≤5002 \le N \le 500) weeks, the rankings of the top MM (2≤M≤5002 \le M \le 500) players each week are given.

Then NN lines follow, each describing one week's ranking. Each line contains MM integers separated by spaces.

  • In each test case there is exactly one player with the highest score.
  • Each week's ranking contains MM distinct player numbers.

A line where NN and MM are both 00 marks the end of the input.

Output

For each test case, print the number(s) of the second-place player(s) on a single line. If two or more players are tied for second place (a tie), print each player number separated by a space in ascending order.

Examples4

  1. Example 1

    Input
    4 5
    20 33 25 32 99
    32 86 99 25 10
    20 99 10 33 86
    19 33 74 99 32
    3 6
    2 34 67 36 79 93
    100 38 21 76 91 85
    32 23 85 31 88 1
    0 0
    
    Expected output
    32 33
    1 2 21 23 31 32 34 36 38 67 76 79 88 91 93 100
    
  2. Example 2

    Input
    2 2
    1 2
    1 3
    0 0
    
    Expected output
    2 3
    
  3. Example 3

    Input
    3 2
    5 7
    5 8
    5 7
    0 0
    
    Expected output
    7
    
  4. Example 4

    Input
    2 2
    1 2
    1 3
    2 2
    4 5
    4 6
    0 0
    
    Expected output
    2 3
    5 6