Experimental Treatment
Time limit2sMemory limit1024 MB
Given n pairs of pill types, pick one type from each pair so that type j is picked exactly c_j times, or report -1 if impossible.
Problem
After many failed attempts to diagnose a new patient, House decided to try an experimental treatment. Throughout the treatment, every hour Foreman offered the patient a choice between two pills. Half an hour after the patient took the -th pill, his health improved sharply and he miraculously survived. The patient remembers how many pills of each type he took, and Foreman remembers every pair of pills he offered. So that doctors can later treat people with the same symptoms, House wants to restore the type of each pill the patient took. He asked you for help.
Input
The first line contains the number of pills the patient took, , and the number of different pill types in the hospital, (, ). Lines 2 through each contain a pair of integers , (, ), the types of pills Foreman offered at hour . The last line contains integers , where is the number of pills of type that the patient took (). Pill types are numbered starting from 1.
Output
Print a sequence of numbers, where the -th number is the type of the pill taken at hour . If there are several answers, you may print any of them. If no answer exists, print a single number .