#K44412. Find the Book on the Shelf
Find the Book on the Shelf
Find the Book on the Shelf
You are given several shelves in a library, each containing a number of books identified by their unique serial numbers. The task is to find the shelf that contains a particular book. Specifically, the library has n shelves and you are provided with a parameter m which is the maximum number of books any shelf can hold. However, note that a shelf may contain fewer than m books.
You will be given the serial numbers of books on each shelf. Your goal is to identify the shelf (using 1-indexing) that contains the query serial number q. If the book does not exist on any shelf, output \(-1\).
Input / Output Format:
Read from standard input (stdin) and output the answer to standard output (stdout).
inputFormat
The input is given in the following format:
- The first line contains two integers n and m separated by a space, where n is the number of shelves and m is the maximum number of books that any shelf can hold.
- The next n lines each describe a shelf. Each shelf description starts with an integer k indicating the number of books on that shelf, followed by k space-separated integers representing the serial numbers of the books.
- The last line contains a single integer q, the serial number of the book to search for.
For example, a sample input could be:
3 4 4 100 200 300 400 3 5 15 25 4 50 60 70 80 60
outputFormat
Output a single integer to stdout: the 1-indexed shelf number containing the book with serial number q. If the book does not exist on any shelf, output \(-1\).
## sample3 4
4 100 200 300 400
3 5 15 25
4 50 60 70 80
60
3