import java.util.Scanner;

public class Task {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] ns = new int[n];
        int[] ms = new int[m];
        for (int i = 0; i < n; i++) {
            ns[i] = in.nextInt();
        }
        for (int i = 0; i < m; i++) {
            ms[i] = in.nextInt();
        }
        int minN = ns[0];
        int minM = ms[0];
        for (int i = 0; i < n; i++) {
            if (ns[i] < minN)
                minN = ns[i];
        }
        for (int i = 0; i < m; i++) {
            if (ms[i] < minM)
                minM = ms[i];
        }
        if(minN == minM)
            System.out.println(minM);
        else if (minN < minM)
            System.out.println(minN + "" + minM);
        else
            System.out.println(minM + "" + minN);
    }
    
}