import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int first=sc.nextInt();
        int second=sc.nextInt();

        ArrayList<Integer> arr1=new ArrayList<>();
        ArrayList<Integer> arr2=new ArrayList<>();
        ArrayList<Integer> arr3=new ArrayList<>();


        for (int i=1; i<=first; i++){
            int a=sc.nextInt();
            arr1.add(a);
        }
        for (int i=1; i<=second; i++){
            int a=sc.nextInt();
            arr2.add(a);
        }
        Collections.sort(arr1);
        Collections.sort(arr2);
        for (int i=0; i<first; i++){
            for (int j=0; j<second; j++){
                if (arr1.get(i) ==arr2.get(j)){
                    arr3.add(arr1.get(i));
                    break;
                }

            }
        }
        Collections.sort(arr3);

        if (arr1.size()==1 && arr2.size()==1){
            if (arr1.get(0)>arr2.get(0))
                System.out.println(arr2.get(0)+""+arr1.get(0));
            else
                System.out.println(arr1.get(0)+""+arr2.get(0));

        }else{
            if (arr3.size()>0){
                System.out.println(arr3.get(0));

            }
            else {
                if (arr1.get(0)>arr2.get(0))
                    System.out.println(arr2.get(0)+""+arr1.get(0));
                else
                    System.out.println(arr1.get(0)+""+arr2.get(0));
            }
        }






    }
}
