eolymp
bolt
Try our new interface for solving problems
Problems

Genetic Engineering

Genetic Engineering

\includegraphics{https://static.e-olymp.com/content/d8/d81547498a7509904b3a43e419a6d2c3fca3b11f.jpg} Genetic engineering - an area of biology dealing with development of new species of animals and plants. Recently, geneticists conducted experiments to create cutlet tree, ie tree, which, instead of apples will grow cutlets. New models created in the laboratory "XX", where they handed over for investigation in two other laboratories. Each sample is complex and costly experiments in each of these laboratories: one analyzed the possibility of chops on crisp, and the second - the productivity of the trees. Results of experiments in each laboratory, placed on a special magazine: \begin{itemize} \item In the first laboratory in the magazine consistently carry the number of samples that have consistently appeared crisp, \item In the second laboratory in its journal consistently carry the number of samples, the yield of which was at least a hundred hamburgers a year. \end{itemize} Experiments were long and complex. In the end, each of the laboratories said that the observations in journals contain the numbers of successful samples. But people need trees, and have those and other property! As a result, there was the task of finding some of the numbers of the sample, which is in the list of successful experiments, each of the laboratories. Vascha task - to write such a program. \textbf{Input } In the first line write the number N (0 ≤ N ≤ 100000) - number of records in the first journal. After a given N numbers arranged in ascending order (a number of good samples from the journal of the first lab). On the next line is given by M, not exceeding 100,000, followed by M numbers, ordered in ascending order. The numbers in the array does not exceed 10^9 in absolute value (a number of good samples from the magazine a second laboratory). \textbf{Output} Display the maximum required number of possible, if it exists. If it's not, then print out the number of -1.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2 1 2
3 2 3 6
Output example #1
2