import java.util.*;
import java.math.*;

public class sdf{

	public static void main(String[] args){

		Scanner in = new Scanner(System.in);

		int l1 = in.nextInt();
		int l2 = in.nextInt();

		int[] ar1 = new int[l1];
		int[] ar2 = new int[l2];

		for(int i = 0 ; i < l1; i++)
			ar1[i] = in.nextInt();

		for(int i = 0 ; i < l2; i++)
			ar2[i] = in.nextInt();		


		Arrays.sort(ar1);
		Arrays.sort(ar2);

		if(ar1[0] == ar2[0] )
			System.out.println(ar1[0]);

		else if( Integer.parseInt(ar1[0] + "" + ar2[0]) > Integer.parseInt(ar2[0] + "" + ar1[0])  )
			System.out.println(Integer.parseInt(ar2[0] + "" + ar1[0]));

		else{
			System.out.println(Integer.parseInt(ar1[0] + "" + ar2[0]));

		}






		

 }}