#P355. 【例61.3】 图书管理员
【例61.3】 图书管理员
Description
Each book in the library has a book code, which is a positive integer used for quick book retrieval.
Each reader has a request code, which is also a positive integer. If a book's code ends with the reader's request code, then this book is what the reader needs.
Little D has just become the library administrator. She knows all the book codes in the library. She asks you to write a program that, for each reader, finds the book with the smallest code that matches their request. If no matching book exists, output .
Input Format
The first line contains two positive integers and , separated by a space, representing the number of books in the library and the number of readers.
The next lines each contain a positive integer, representing a book code in the library.
The next lines each contain two positive integers, separated by a space. The first integer represents the length of the reader's request code, and the second integer represents the reader's request code.
, , all book codes and request codes are no more than .
Output Format
Output lines, each containing one integer. If there exists a book matching the -th reader's request, output the smallest book code that matches the request on the -th line. Otherwise, output .
Sample
5 5
2123
1123
23
24
24
2 23
3 123
3 124
2 12
2 1223
1123
-1
-1
-1