import java.util.*;
import java.lang.*;
import java.io.*;
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();	
		int m=sc.nextInt();
		int[] arr1 = new int[n];
		int[] arr2 = new int[m];
		int[] merge = new int[arr1.length+arr2.length];
		for(int i=0;i<n;i++)
		{
			arr1[i]=sc.nextInt();
			merge[i]=arr1[i];
		}
		for(int i=0;i<m;i++)
		{
			arr2[i]=sc.nextInt();
			merge[n+i]=arr2[i];
		}
		Arrays.sort(arr1);
		Arrays.sort(arr2);
		Arrays.sort(merge);
		for(int i=0;i+1<merge.length;i++){
			if(merge[i]==merge[i+1] ){
			System.out.println(merge[i]);
			System.exit(0);
			}	
		}
		int a1=arr1[0]*10+arr2[0];
		int a2=arr2[0]*10+arr1[0];
		System.out.println(Math.min(a1,a2));
	}
}