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

public class prettyIntegers {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int [] arr1 = new int[n];
		int [] arr2 = new int[m];
		for (int i=0;i<n;i++) {
			arr1[i] = sc.nextInt();
		}
		for (int i=0;i<m;i++) {
			arr2[i] = sc.nextInt();
		}
		
		for (int i=1;i<=9;i++) {
			if (pres(i,arr1)&&pres(i,arr2)) {
				System.out.println(i);
				return;
			}
		}
		int min1 = min(arr1);	int min2=min(arr2);
		System.out.println(Math.min(min1, min2)*10 + Math.max(min1, min2));
		
	
	}
	public static boolean pres(int x,int[] arr) {
		for (int i=0;i<arr.length;i++) {
			if (arr[i]==x) return true;
		}
		return false;
	}
	public static int min(int[] arr) {
		int min = Integer.MAX_VALUE;
		for (int i=0;i<arr.length;i++)
			if(arr[i]<min) min = arr[i];
		return min;
	}
	
}
