P2961 [USACO09NOV] Who Brings the Cookies? G

Description

Farmer John's N (1

Input Format

\* Line 1: Two space-separated integers: N and M \* Lines 2..M+1: Line i+1 contains many space-separated integers: S\_i, G\_i1, G\_i2, ...

Output Format

\* Lines 1..M: If a mapping is possible, line i contains the number of the cow who brings cookies to study group i. Otherwise, line 1 contains just the integer -1.

Explanation/Hint

Cow1 can bring cookies to at most 2 meetings, cow2 can bring 2, cow3 can bring 2, cow4 can bring 1, and cow5 can bring 1.