import java.util.Scanner;
import java.util.Arrays;

public class CF870A {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] na = new int[n];
        int[] ma = new int[m];
        for(int i = 0; i < n; i++){
            na[i] = sc.nextInt();
        }
        for(int i = 0; i < m; i++){
            ma[i] = sc.nextInt();
        }
        Arrays.sort(na);
        Arrays.sort(ma);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(na[i] == ma[j]) {
                    System.out.print(na[i]);
                    return ;
                }
            }
        }
        System.out.println(na[0] + " " + ma[0]);
    }
}