import java.util.Scanner;

public class SearchforPrettyIntegers {

    public static void main (String[] args){
        Scanner reader = new Scanner(System.in);
        int[] list1;
        int[] list2;
        int n,m;
        int answer = Integer.MAX_VALUE;

        n = reader.nextInt();
        m = reader.nextInt();

        list1 = new int[n];
        list2 = new int[m];

        for (int i = 0 ; i < n ; ++i )
            list1[i] = reader.nextInt();

        for (int i = 0 ; i < m ; ++i )
            list2[i] = reader.nextInt();


        for (int i = 0 ; i < n ; ++i )
            for (int j = 0 ; j < m ; ++j )
                if (list1[i] == list2[j])
                    answer = Integer.min(answer, list1[i]);
                else{
                    answer = Integer.min(answer,list1[i]*10 + list2[j]);
                    answer = Integer.min(answer,list2[j]*10 + list1[i]);
                }


        System.out.println(answer);

    }
}
