import java.util.Arrays;
import java.util.Scanner;

public class SearchForPrettyIntegers {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for(int i = 0; i < n; i++) a[i] = s.nextInt();
        for(int i = 0; i < m; i++) b[i] = s.nextInt();
        Arrays.sort(a);
        Arrays.sort(b);
        int first = a[0];
        int second = b[0];
        if(first == second) System.out.println(first);
        else System.out.println(first >= second ? 10 * second + first : 10 * first + second);
    }
}
