import java.util.Scanner;

/**
 *
 * @author Sonicxd2
 */
public class Main {
    
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int[] arr = new int[a];
        
        for(int i = 0; i<a; i++)
            arr[i] = sc.nextInt();
        
        int[] arr2 = new int[b];
        
        for(int i = 0; i<b; i++)
            arr2[i] = sc.nextInt();
        
        for(int i = 1; i<99; i++){
            boolean found = false;
            for(int j = 0; j<a; j++)
                found = found || (i/10>0?i/10 == arr[j]:false) || i%10 == arr[j];
            if(!found)
                continue;
            
            found = false;
            
            for(int j = 0; j<b; j++)
                found = found || (i/10>0?i/10 == arr2[j]:false) || i%10 == arr2[j];
            
            if(found){
                System.out.println(i);
                return;
            }
        }
        
        
    }
    
}