B - Representative Balls Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 個のボールがあります。

i 番目のボールの色は C_i、大きさは S_i です。ここで、色は 1, 2, \ldots, M の整数で表されます。

k = 1, 2, \ldots, M について、色 k のボールの大きさの最大値を出力してください。ただし、色 k のボールが存在しない場合は -1 と出力してください。

制約

  • 1 \leq N, M \leq 100
  • 1 \leq C_i \leq M
  • 1 \leq S_i \leq 100
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M
C_1 S_1
C_2 S_2
\vdots
C_N S_N

出力

k = 1, 2, \ldots, M の順に、色 k のボールが存在するならば色 k のボールの大きさの最大値を、存在しないならば -1 を空白区切りで出力せよ。


入力例 1

4 5
1 3
2 10
1 7
4 9

出力例 1

7 10 -1 9 -1

1 のボールの大きさの最大値は 7、色 2 のボールの大きさの最大値は 10、色 4 のボールの大きさの最大値は 9 です。

3 のボール、色 5 のボールは存在しません。


入力例 2

5 5
2 6
5 12
5 2
5 9
2 7

出力例 2

-1 7 -1 -1 12

Score : 200 points

Problem Statement

There are N balls.

The color of the i-th ball is C_i, and its size is S_i. Here, the colors are represented by integers 1, 2, \ldots, M.

For k = 1, 2, \ldots, M, output the maximum size of a ball of color k, or -1 if there is no ball of color k.

Constraints

  • 1 \leq N, M \leq 100
  • 1 \leq C_i \leq M
  • 1 \leq S_i \leq 100
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M
C_1 S_1
C_2 S_2
\vdots
C_N S_N

Output

In the order k = 1, 2, \ldots, M, output the maximum size of a ball of color k if such a ball exists, or -1 otherwise, separated by spaces.


Sample Input 1

4 5
1 3
2 10
1 7
4 9

Sample Output 1

7 10 -1 9 -1

The maximum size of a ball of color 1 is 7, that of a ball of color 2 is 10, and that of a ball of color 4 is 9.

There is no ball of color 3 or color 5.


Sample Input 2

5 5
2 6
5 12
5 2
5 9
2 7

Sample Output 2

-1 7 -1 -1 12