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

public class SearchForPrettyIntegers {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n, m;
        n = scanner.nextInt();
        m = scanner.nextInt();
        int[] arr1, arr2, freq;
        arr1 = new int[n];
        arr2 = new int[m];
        freq = new int[10];

        for(int i  = 0; i < n; i++) {
            arr1[i] = scanner.nextInt();
            freq[arr1[i]]++;
        }
        for(int i = 0; i < m; i++) {
            arr2[i] = scanner.nextInt();
            freq[arr2[i]]++;
        }
        int ans = -1;
        for(int i = 1; i <= 9; i++) {
            if (freq[i] == 2) {
                ans = i;
                break;
            }
        }
        if (ans == -1) {
            Arrays.sort(arr1);
            Arrays.sort(arr2);
            int a, b;
            a = arr1[0];
            b = arr2[0];
            if (a < b) ans = a * 10 + b;
            else ans = b * 10 + a;
        }
        System.out.println(ans);
    }
}
