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

public class Pretty {
	public static void main(String []args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int []a = new int[n];
		int []b = new int[m];
		for(int i=0;i<n;i++)
		{
			int temp = sc.nextInt();
			a[i] = temp;
		}
		for(int i=0;i<m;i++)
		{
			int temp = sc.nextInt();
			b[i] = temp;
		}
		int flag = 0;
		Arrays.sort(a);
		Arrays.sort(b);
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(a[i] == b[j])
				{
					System.out.println(a[i]);
					flag = 1; 
					break;
				}
			}
			if(flag == 1)
				break;
		}
		int i=0,j=0;
		if(flag == 0)
		if(a[i] > b[j])
			System.out.println(b[j]*10+a[i]);
		else
			System.out.println(a[i]*10+b[j]);
		
	}

}
