import java.util.*;

public class PrettyIntegers {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int m = input.nextInt();

        List<Integer> firstList = new ArrayList<>();
        for(int i = 0; i < n; i++)
            firstList.add(input.nextInt());

        List<Integer> secondList = new ArrayList<>();
        for(int j = 0; j < m; j++)
            secondList.add(input.nextInt());

        Collections.sort(firstList);
        if(secondList.contains(firstList.get(0)))
            System.out.println(firstList.get(0));
        else {
            Collections.sort(secondList);
            System.out.printf("%d%d%n", firstList.get(0), secondList.get(0));
        }
    }
}