import java.util.Scanner;
import java.util.TreeSet;

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

        TreeSet<Integer> a = new TreeSet<>();
        TreeSet<Integer> b = new TreeSet<>();

        for (int i = 0; i < n; i++) {
            a.add(input.nextInt());
        }

        for (int i = 0; i < m; i++) {
            b.add(input.nextInt());
        }
        int s1 = a.first();
        int s2 = b.first();
        while (!a.isEmpty()) {
            int k = b.size();
            Integer i = a.pollFirst();
            b.add(i);
            if (b.size() == k) {
                System.out.println(i);
                return;
            }
        }
        if (s1 * 10 + s2 > s2 * 10 + s1) {
            System.out.println((s2 * 10) + s1);
        } else {
            System.out.println((s1 * 10) + s2);
        }

    }
}

  	 		 		 	  	  				   		  	  	