import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Test1 {
    public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        Integer t[] = {in.nextInt(), in.nextInt()}, a[][] = new Integer[2][];

        for(int i = 0; i<2; i++) {
            a[i] = new Integer[t[i]];
            for (int j = 0; j < t[i]; j++)
                a[i][j] = new Integer(in.nextInt());
        }

        Set<Integer> ans = new TreeSet<>();
        for(int i = 0; i<t[0]; i++){
            for(int j = 0; j<t[1]; j++){
                ans.add((int)a[0][i]==a[1][j]?a[0][i]:min(a[0][i], a[1][j])*10+max(a[0][i], a[1][j]));
            }
        }
        ans.forEach(p->{
            System.out.print(p);
            System.exit(0);
        });
    }
}