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

/**
 *
 * @author iqtid
 */
public class Pretty_integers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scanner = new Scanner(System.in);
        int min = 0;
        int result = Integer.MAX_VALUE;
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int a[] = new int[m];
        int b[] = new int[n];
        for(int i=0;i<m;i++) a[i] = scanner.nextInt();
        for(int j=0;j<n;j++) b[j] = scanner.nextInt();
        Arrays.sort(a);
        Arrays.sort(b);
        for(int i=0;i<m;i++) {
            for(int j=0;j<n;j++) {
                if(a[i]==b[j]){
                    System.out.println(a[i]);
                    return;
                }
                else {
                     min = Math.min(a[i],b[j])*10 + Math.max(a[i],b[j]);
                     if(min<result) {
                         result = min;
                     }
                }
            }
        }
        System.out.println(result);
    }
    
}
