cho.sh
Notes
Loading...

Candidate Recommendation

Time limit

2s

Memory limit

128 MB

Problem

World Elementary School chooses student council candidates from student recommendations. There are N photo frames where candidate photos can be displayed. Process each recommendation using the following rules.

  1. Before recommendations begin, every photo frame is empty.
  2. When a student is recommended, that student's photo must be displayed in a frame.
  3. If there is no empty frame, remove the photo of the displayed student with the fewest recommendations so far, then display the newly recommended student. If several displayed students have the fewest recommendations, remove the one whose photo has been displayed the longest.
  4. If a student who is already displayed is recommended again, keep the photo and increase only that student's recommendation count by 1.
  5. When a student's photo is removed, that student's recommendation count is reset to 0.

Given the number of frames and the recommended student numbers in order, determine which students remain as candidates at the end.

Input

The first line contains the number of photo frames N. (1 <= N <= 20)

The second line contains the total number of recommendations. The number of recommendations is at most 1,000.

The third line contains the recommended student numbers in recommendation order, separated by spaces. Each student number is a natural number from 1 to 100.

Output

Print the student numbers that remain in the photo frames at the end, in increasing order.