import java.io.*;
import java.util.*;
import java.lang.*;
    public class aim
    {
        public static void main(String args[])throws IOException
            {
            Scanner sc = new Scanner(System.in);
            int n=sc.nextInt();
            int m=sc.nextInt();
            
           int a[]=new int[n];
           int b[]=new int[m];
           for(int i=0;i<n;i++)
           a[i]=sc.nextInt();
           
           for(int i=0;i<m;i++)
           b[i]=sc.nextInt();
           
           Arrays.sort(a);
           Arrays.sort(b);
           int ans=0;int min =Integer.MAX_VALUE;
           for(int i=0;i<Math.min(m,n);i++)
           {
               int k=a[i];
               int j=find(b,k,0,m-1);
               if(j==1)
               {
                   ans=k;
                   if(ans<min)
                   min = ans;
                   break;
               }
               
               else
               {
                   if(a[0]>b[0])
                        {
                             ans= b[0]*10 + a[0];
                             if(ans<min)
                             min =ans;
                        }
                    else if(b[0]>a[0])
                        {
                            ans =a[0]*10 +b[0];
                            if(ans<min)
                            min =ans;
                        }
                    else 
                        {    
                            ans =a[0];
                            if(ans<min)
                            min =ans;
                        }
                   
                   
               }
               
           }
           if(ans<=min)
               System.out.println(min);
           
        }
        
        static int find(int a[],int k,int l,int h)
        {
            while(l<=h)
            {
                int mid = (l+h)/2;
            
            if(a[mid]==k)
            return 1;
             if(a[mid]<k)
            {
                return find(a,k,mid+1,h);
            }
             if(a[mid]>k)
            return find(a,k,l,mid-1);
            }
            return 0;
             
        
            
        }
    }