import java.util.*;
public class Search_for_Pretty_Integers 
{
	public static void main(String ar[])
	{
		Scanner s1 = new Scanner(System.in);
		int n,m;
		n = s1.nextInt();
		m = s1.nextInt();
		int a[] = new int[10];
		int b[] = new int[10];
		Arrays.fill(a,0);
		Arrays.fill(b,0);
		for(int i=0;i<n;i++)
			a[s1.nextInt()]++;
		for(int i=0;i<m;i++)
			b[s1.nextInt()]++;
		int mina=10,minb=10;
		for(int i=1;i<10;i++)
		{
			if(a[i] == 1 && mina == 10)
				mina = i;
			if(b[i] == 1 && minb == 10)
				minb = i;
			if(mina != 10 && minb != 10)
				break;
		}
		if(mina == minb)
			System.out.println(mina);
		else if(mina>minb)
			System.out.println(minb+""+mina);
		else
			System.out.println(mina+""+minb);
		s1.close();
	}
}	