import java.util.Scanner;

public class CF_870A 
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        int n,m,min = 9,min1 = 9;
        int ar1[] = new int [1000];
        int ar2[] = new int [1000];
        n = sc.nextInt();
        m = sc.nextInt();
        
        for(int a=0;a<=n-1;a++)
        {
            ar1[a] = sc.nextInt();
            if(min>ar1[a])
                min=ar1[a];
        }
        
        for(int b=0;b<=m-1;b++)
        {
            ar2[b] = sc.nextInt();
            if(min1>ar2[b])
                min1=ar2[b];
        }
        
        if(m==1)
            System.out.println("" + ar2[m-1]);
        else if(n==1)
            System.out.println("" + ar1[n-1]);
        else if(min==min1)
            System.out.println("" + min);
        else if(min>min1)
            System.out.println("" + min1 + "" + min);
        else if(min1>min)
            System.out.println("" + min + "" + min1);
    }
}
