/**
 * Created by hailoc12 on 10/19/2017.
 */
import java.util.Scanner;
import java.util.Arrays;
public class SearchForPrettyIntegers_870_A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        int[] list1 = new int[n];
        int[] list2 = new int[m];

        for(int i=0; i<n; i++) list1[i] = in.nextInt();
        for(int i=0; i<m; i++) list2[i] = in.nextInt();

        Arrays.sort(list1);
        Arrays.sort(list2);

        int minValue;
        if(list1[0] != list2[0]){
            minValue = list1[0] * 10 + list2[0];
        }
        else{
            minValue = list1[0];
        }

        int tmpValue;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(list1[i] > list2[j]){
                    tmpValue = list2[j] * 10 + list1[i];
                }
                else if(list1[i] < list2[j]){
                    tmpValue = list1[i] * 10 + list2[j];
                }
                else{
                    tmpValue = list1[i];
                }

                if(tmpValue < minValue) minValue = tmpValue;
            }
        }

        System.out.println(minValue);
    }
}
