
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];
		
		int[] arr = new int[10];
		int[] brr = new int[10];
		for(int i=0;i<n;i++) {
		    list1[i] = sc.nextInt();
		    arr[list1[i]]++;
		}
		for(int i=0;i<m;i++) {
		    list2[i] = sc.nextInt();
		    brr[list2[i]]++;
		}
		
		int res = 0;
		
		for(int i=0;i<10;i++){
		    if(arr[i]!=0 && brr[i]!=0){
		        res = i;
		        System.out.println(res);
		        return;
		    }
		    
		}
		
		
		Arrays.sort(list1);
		Arrays.sort(list2);
	
		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);
		
	}
}
