/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	static int solution(int[] A, int[] B) {
        int n = A.length;
        int m = B.length;

        Arrays.sort(A);
        Arrays.sort(B);

        int i = 0;
        int j = 0;
        while (i < n && j < m) {
            if (A[i] == B[j]) 
                return A[i];
            else {
            	if (A[i] > B[j]) 
                    j++;
                else
                    i++;
            }
        }     
        return -1;
    }
	public static void main (String[] args) throws java.lang.Exception
	{
		int[] x1 = {0, 2, 7, 10, 23, 345, 56, 456, 767, 56, 6, 80, 6, 65}; 
		int[] y1= {1, 4, 5, 9, 9, 9, 80, 67, 77};
        System.out.print(solution(x1,y1));
	}
}