
import java.io.*;
import java.util.*;
 
public class Sum
{
      
    public static void main(String[] args)
    {

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
   int e=0;
        int n=in.nextInt();
        int m =in.nextInt();
        boolean[] first = new boolean[10];
       boolean[] second = new boolean[10];
        
        for (int i=0;i<n;i++)
        {
        first[in.nextInt()]=true;	
        }
        for (int i=0;i<m;i++)
        {
        second[in.nextInt()]=true;	
        }
     for (int i=1;i<10;i++)
     {
    	 if (first[i]&&second[i])
    	 {
    		 e=i;
    		 break;
    	 }
     }
     if (e==0)
     {
    	 int min1=0;
    	 int min2=0;
    	 for (int i=1;i<10;i++)
         {
         if (first[i])
         {
        	 min1=i;
        	 break;
         }
         }
         for (int i=1;i<10;i++)
         {
         if (second[i])
         {
        	 min2=i;
        	 break;
         }
         }
         if (min2<min1)
         {
        	 e=min2*10+min1;
        	 
         }
         else
         {
        	 e=min1*10+min2;
         }
     }
    			 
out.println(e);
        in.close();
        out.flush();
      out.close();
    
    
}
    
public static boolean god(char b)
{
	boolean go=false;
	if (b!='a'&&b!='e'&&b!='i'&&b!='o'&&b!='u')
	{
		go=true;
	}

	return(go);
}
}
