import java.math.*;
import java.util.*;
public class Main {
    static void test_bigdecimal(){
        BigDecimal a = new BigDecimal(117.123);
        BigDecimal b = new BigDecimal(5.2);
        BigDecimal c = a.divide(b,BigDecimal.ROUND_HALF_DOWN);
        System.out.println(c);
        System.out.println(c.setScale(10,BigDecimal.ROUND_DOWN));

    }
    static void test_biginteger(){
        BigInteger a = new BigInteger("123");
        BigInteger b = BigInteger.valueOf(33333);
        System.out.println(a.mod(b));
        System.out.println(a.remainder(b));

    }
    static int a[],b[],vis[];
    static {
        a = new int[10];
        b = new int[10];
        vis = new int[10];
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m = sc.nextInt();
        int m1 = 10,m2 = 10;
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
            vis[a[i]]++;
            m1 = Integer.min(m1,a[i]);
        }
        for(int i = 0;i<m;i++){
            b[i] = sc.nextInt();
            vis[b[i]]++;
            m2 = Integer.min(m2,b[i]);
        }
        for(int i = 0;i<9;i++){
            if(vis[i] == 2){
                System.out.println(i);
                return;
            }
        }
        System.out.printf("%d\n",Integer.min(m1*10+m2,m2*10+m1));
    }
}
