import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int m = in.nextInt();
        int[] a = new int[m];
        int n = in.nextInt();
        int[] b = new int[n];
        in.nextLine();
        for (int i =0;i<m; i++) {
            a[i] = in.nextInt();
        }
        in.nextLine();
        for (int i =0;i<n; i++) {
            b[i] = in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);

        int result;

        int r1 = Integer.valueOf(a[0] + "" + b[0]);
        int r2 = Integer.valueOf(b[0] + "" + a[0]);

        if (a[0] == b[0]) {
            result = a[0];
        } else {
            if (r1 > r2) {
                result = r2;
            } else {
                result = r1;
            }
        }

        out.println(result);
        out.flush();
    }
}