//package codeforces;

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

public class BeautifulNumbers {


	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] firstLine = new int[scanner.nextInt()];
		int[] secondLine = new int[scanner.nextInt()];
		int[] naturals = new int[9];

		for (int i = 0; i < firstLine.length; i++) {
			firstLine[i] = scanner.nextInt();
		}
		for (int i = 0; i < secondLine.length; i++) {
			secondLine[i] = scanner.nextInt();
		}
		Arrays.sort(firstLine);
		Arrays.sort(secondLine);
		int k = 0;
		for (int i = 0; i < firstLine.length; i++) {
			for (int j = 0; j < secondLine.length; j++) {
				if (firstLine[i] == secondLine[j]) {
					naturals[k] = firstLine[i];
					k++;
				}
			}
		}
		Arrays.sort(naturals);
//		System.out.println(Arrays.toString(naturals));
		int minNatural = Math.min(firstLine[0], secondLine[0])*10 + Math.max(firstLine[0], secondLine[0]);
		if (naturals[1] != 0) {
			System.out.println(naturals[1]);
		}
		else 
			System.out.println(minNatural);

		scanner.close();

	}

}
