import java.util.Scanner;

public class technocup {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int minN = 10;
        int minM = 10;
        int n = input.nextInt();
        int[] masivN = new int[n];
        int m = input.nextInt();
        int[] masivM = new int[m];
        for (int i = 0; i < n; i++) {
            masivN[i] = input.nextInt();
            if (masivN[i] < minN) { minN = masivN[i]; }
        }
        for (int i = 0; i < m; i++) {
            masivM[i] = input.nextInt();
            if (masivM[i] < minM) { minM = masivM[i]; }
        }
        if (minN == minM) {
            System.out.println(minN);
        }else{
            if (minN < minM) {
                System.out.print(minN);
                System.out.print(minM);
            }else{
                System.out.print(minM);
                System.out.println(minN);
            }
        }
    }
}