import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{	
	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();
		}
		Arrays.sort(arr1);
		Arrays.sort(arr2);
		int x=0,y=0;
		x=arr1[0];
		y=arr2[0];
		//System.out.println(x+" "+y);
		if(x!=y){System.out.println(Math.min(x,y)+""+Math.max(x,y));}
		else System.out.println(x);

		
	}

}
