import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l1 = sc.nextInt();
        int l2 = sc.nextInt();
        int arr1[] = new int[10];
        int arr2[] = new int[10];
        for (int i = 0; i < l1; i++) {
            arr1[sc.nextInt()]++;
        }
        for (int i = 0; i < l2; i++) {
            arr2[sc.nextInt()]++;
        }
        boolean flag = false;
        for (int i = 0; i < 9; i++) {
            if (arr1[i] >= 1 && arr2[i] >= 1) {
                System.out.println(i);
                flag = true;
                break;
            }
        }
        String s=new String();
        if (!flag) {
          outer:  for (int i = 0; i < 9; i++) {
                if(arr1[i]!=0){
                    for (int j = 0; j < 9; j++) {
                        if(arr2[j]!=0){
                            if(j>i){
                                System.out.println(i+""+j);
                            }else{
                                System.out.println(j+""+i);
                            }
                            break outer;
                        }
                    }
                }
            }
        }
    }
}
