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<>();
        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);
        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 (arr1.get(0) == arr2.get(0))
                System.out.println(arr1.get(0));
            else
                System.out.println(arr1.get(0) + "" + arr2.get(0));
        }



    }
}
