import java.util.Scanner;

public class pretty_integers {
    public static void main(String[] args) {
        Scanner key=new Scanner(System.in);
        
        int n=key.nextInt();int m=key.nextInt();
        
        int[] a=new int[n];
        int[] b=new int[m];
        int smalln=Integer.MAX_VALUE;
        int smallm=Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            a[i]=key.nextInt();
            if(smalln>a[i]){
              smalln=a[i];    
             }
            
        }
        for(int i=0;i<m;i++){
            b[i]=key.nextInt();
             if(smallm>b[i]){
              smallm=b[i];    
             }
        }
        if(smalln==smallm){
            System.out.println(smalln);
        }
        else if(smallm>smalln){
            System.out.println(smalln+""+smallm);
        }
        
        else if(smalln>smallm){
            System.out.println(smallm+""+smalln);
    }}
}