import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int c = sc.nextInt();
            if (c < min && c != 0)
                min = c;
        }
        for (int i = 0; i < m; i++) {
            int c = sc.nextInt();
            if (c < min2)
                min2 = c;
        }
        if (min == min2)
            System.out.println(min);
        else if (min < min2)
            System.out.println(min + "" + min2);
        else
            System.out.println(min2 + "" + min);

    }
}
