import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a1 = new int[n];
        int m = sc.nextInt();
        int[] a2 = new int[m];
        int min=9;
        int min1=9;
        int min2=9;
        int temp=0;
        for (int i=0; i<n; ++i){
            a1[i]=sc.nextInt();
            if (a1[i]<min1)
                min1=a1[i];
        }
        for (int i=0; i<m; ++i){
            a2[i]=sc.nextInt();
            for (int j=0; j<n; ++j){
                if (a2[i]==a1[j] && a1[j]<=min){
                    min=a1[j];
                    temp=1;
                }
            }
            if (a2[i]<min2)
                min2=a2[i];
        }
        if (temp==1)
            System.out.println(min);
        else{
            if (min1<min2)
                System.out.println(min1+""+min2);
            else
                System.out.println(min2+""+min1);  
        }      
    }
}