import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.Stream;

@SuppressWarnings("ALL")
public class Problem870A {
    public static void main(String[] args) throws IOException  {
        try (BufferedReader z = new BufferedReader(new InputStreamReader(System.in))) {
            z.readLine();
            String[] a = z.readLine().split(" ");
            String[] b = z.readLine().split(" ");
            HashSet<String> h = new HashSet<String>(Arrays.asList(a));
            h.retainAll(new HashSet<>(Arrays.asList(b)));
            if (!h.isEmpty()) {
                String[] s = new String[h.size()];
                h.toArray(s);
                System.out.println(Stream.of(s).mapToInt(Integer::valueOf).min().getAsInt());
            } else {
                int min1 = Stream.of(a).mapToInt(Integer::valueOf).min().getAsInt();
                int min2 = Stream.of(b).mapToInt(Integer::valueOf).min().getAsInt();
                System.out.println(min1 == min2 ? min1 : min1 < min2 ? min1 * 10 + min2 : min2 * 10 + min1);
            }
        }
    }
}
