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];
		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);
		if(arr1[0]==arr2[0]){
			System.out.println(arr1[0]);
		}
		else{
			int a1=arr1[0]*10+arr2[0];
			int a2=arr2[0]*10+arr1[0];
			System.out.println(Math.min(a1, a2));
		}
	}
}