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

public class Main
{
    
    
	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[] list1 = new int[n];
		int[] list2 = new int[m];
		for(int i=0;i<n;i++) list1[i] = sc.nextInt();
		for(int i=0;i<m;i++) list2[i] = sc.nextInt();
		
		Arrays.sort(list1);
		Arrays.sort(list2);
		int res = 0;
		if(list1[0]==list2[0]) res = list1[0];
		else if(list1[0]<list2[0]) res = 10*list1[0] + list2[0];
		else res = 10*list2[0] + list1[0];
		System.out.println(res);
		
	}
}
