import java.util.Scanner;

public class BeautifulNumberSearch {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] arrayOne = new int[n];
        int[] arrayTwo = new int[m];
        findMinWhileScanning(arrayOne, scanner);
        findMinWhileScanning(arrayTwo, scanner);

        if (arrayOne[0] == arrayTwo[0]) {
            System.out.println(arrayOne[0]);
        } else {
            System.out.print(Math.min(arrayOne[0], arrayTwo[0]));
            System.out.print(Math.max(arrayOne[0], arrayTwo[0]));
        }

    }

    static void findMinWhileScanning(int[] array, Scanner sc) {
        for (int i = 0; i < array.length; i++) {
            array[i] = sc.nextInt();
            if (i > 0) {
                for (int j = i; j > 0; j--) {
                    if (array[j] < array[j - 1]) {
                        int temp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j] = temp;
                    }
                }
            }
        }

    }

}