import java.util.Scanner;


public class taskA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n,m;

        n= sc.nextInt();
        m = sc.nextInt();

        int [] a = new int [n];
        int [] b = new int [m];

        for (int i =0; i<n; i++){
            a[i]=sc.nextInt();
        }

        for (int i =0; i<m; i++){
            b[i]=sc.nextInt();
        }
        int min1,min2;

       min1 = a[0];
       min2 = b[0];


        for (int i = 0;i<a.length; i++){
            if(a[i]<min1){
                min1 = a[i];
            }
        }
        for (int i = 0;i<b.length; i++){
            if(b[i]<min2){
                min2 = b[i];
            }
        }
        if(min1>min2){
        System.out.println(min2+""+min1);
        } else {
            System.out.println(min1+""+min2);
        }
    }
}
