import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int b=10,a=10;
        for(int i=0;i<n;i++){
            int k = scan.nextInt();
            a=Math.min(a,k);
        }
        for(int i=0;i<m;i++){
            int k = scan.nextInt();
            b=Math.min(b,k);
        }
        if (a==b) System.out.println(a);
        else {System.out.print(Math.min(a,b));System.out.print(Math.max(a,b));}
    }
}
