#P1571F. Kotlinforces

    ID: 1848 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>*special problemconstructive algorithmsdp*2000

Kotlinforces

Description

Kotlinforces is a web platfrom that hosts programming competitions.

The staff of Kotlinforces is asked to schedule nn programming competitions on the next mm days. Each competition is held in multiple stages; the regulations of the ii-th competition state that this competition should consist of exactly kik_i stages, and each stage, starting from the second one, should be scheduled exactly tit_i days after the previous stage. In other words, if the first stage of the ii-th competition is scheduled on day xx, the second stage should be scheduled on day x+tix+t_i, the third stage — on day x+2tix+2t_i, ..., the kik_i-th stage (which is the last one) — on day x+(ki1)tix+(k_i-1)t_i.

All nn competitions should be scheduled in such a way that they start and finish during the next mm days, and on any of these mm days, at most one stage of one competition is held (two stages of different competitions should not be scheduled on the same day).

Is it possible to schedule all nn competitions to meet these constraints?

The first line contains two integers nn and mm (1n,m50001 \le n, m \le 5000) — the number of competitions and the number of days, respectively.

Then nn lines follow, each describing a competition which should be scheduled. The ii-th line contains two integers kik_i and tit_i (2ki50002 \le k_i \le 5000; 1ti21 \le t_i \le 2) — the parameters of the ii-th competition.

If it is impossible to schedule all nn competitions on the next mm days so that there is at most one stage during each day, print -1.

Otherwise, print nn integers. The ii-th integer should represent the day when the first stage of the ii-th competition is scheduled; days are numbered from 11 to mm. If there are multiple answers, print any of them.

Input

The first line contains two integers nn and mm (1n,m50001 \le n, m \le 5000) — the number of competitions and the number of days, respectively.

Then nn lines follow, each describing a competition which should be scheduled. The ii-th line contains two integers kik_i and tit_i (2ki50002 \le k_i \le 5000; 1ti21 \le t_i \le 2) — the parameters of the ii-th competition.

Output

If it is impossible to schedule all nn competitions on the next mm days so that there is at most one stage during each day, print -1.

Otherwise, print nn integers. The ii-th integer should represent the day when the first stage of the ii-th competition is scheduled; days are numbered from 11 to mm. If there are multiple answers, print any of them.

Sample Input 1

3 7
3 2
2 2
2 2

Sample Output 1

2 5 1

Sample Input 2

1 7
4 2

Sample Output 2

1

Sample Input 3

1 7
5 2

Sample Output 3

-1

Sample Input 4

2 4
2 1
2 2

Sample Output 4

-1

Sample Input 5

2 5
2 1
2 2

Sample Output 5

4 1