import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class SearchForPrettyIntegers {

    public static ArrayList<Integer> commonItems(int[] a, int[] b) {
        ArrayList<Integer> res = new ArrayList<>();
        for(int i = 0; i < a.length; i++) {
            for(int j = 0; j < b.length; j++) {
                if(a[i] == b[j]) res.add(a[i]);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for(int i = 0; i < n; i++) a[i] = s.nextInt();
        for(int i = 0; i < m; i++) b[i] = s.nextInt();
        Arrays.sort(a);
        Arrays.sort(b);
        ArrayList<Integer> common = commonItems(a, b);
        if(common.size() > 0) System.out.println(common.get(0));
        else {
            int first = a[0];
            int second = b[0];
            System.out.println(first >= second ? 10 * second + first : 10 * first + second);
        }
    }
}
