import java.util.Arrays;
import java.util.Scanner;
public class Pretty_Integers {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int m=in.nextInt();
        int n=in.nextInt();
        String X="";
        int [] a=new int[m];
        int [] b=new int [n];
        for (int i = 0; i < m; i++) {
            a[i]=in.nextInt();            
        }
        for (int i = 0; i < n; i++) {
            b[i]=in.nextInt();            
        }
        Arrays.sort(a);
        Arrays.sort(b);
        if(a[0]==b[0])
            X+=a[0];
        else{
            if(a[0]<b[0])
                X+=a[0]+""+b[0];
            else
                X+=b[0]+""+a[0];
        }
        System.out.println(X);
    }
    
}
