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());

        Set<Integer> firstSet = new TreeSet<>(firstList);
        Set<Integer> secondSet = new TreeSet<>(secondList);

        firstList.clear();
        firstList.addAll(firstSet);

        secondList.clear();
        secondList.addAll(secondSet);

        List<Integer> answers = new ArrayList<>();
        for(Integer integer : firstList)
            if(secondList.contains(integer))
                answers.add(integer);

        for(Integer integer : secondList)
            if(firstList.contains(integer))
                answers.add(integer);
            
        if(!answers.isEmpty()) {
            System.out.println(Collections.min(answers));
            return;
        }

        if(!firstList.get(0).equals(0))
            answers.add(Integer.parseInt(String.format("%d%d", firstList.get(0), secondList.get(0))));
        else
            answers.add(Integer.parseInt(String.format("%d%d", firstList.get(1), secondList.get(0))));

        if(!secondList.get(0).equals(0))
            answers.add(Integer.parseInt(String.format("%d%d", secondList.get(0), firstList.get(0))));
        else
            answers.add(Integer.parseInt(String.format("%d%d", secondList.get(1), firstList.get(0))));

        System.out.println(Collections.min(answers));
    }
}