import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int size1=sc.nextInt();
        int size2=sc.nextInt();
        int[] arr1=new int[size1];
        int[] arr2=new int[size2];
        for(int i=0;i<size1;i++)arr1[i]=sc.nextInt();
        for(int i=0;i<size2;i++)arr2[i]=sc.nextInt();
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        if(arr1[0]==arr2[0])System.out.println(arr1[0]);
        else System.out.println(arr1[0]+""+arr2[0]);
    }
}