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

public class JavaApplication1 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x = sc.nextInt();
                int y = sc.nextInt();
		int[] a = new int[x], b = new int[y];
		for(int i = 0; i<x; i++) a[i] = sc.nextInt();
		for(int i = 0; i<y; i++) b[i] = sc.nextInt();
		Arrays.sort(a);
		Arrays.sort(b);
		for(int i = 0; i<y; i++) {
			for(int j = 0; j<x; j++) {
				if(a[j] == b[i]) {System.out.println(a[j]); return;}
			}
		}
		int i1 = Integer.parseInt(a[0]+ "" + b[0]);
		int i2 = Integer.parseInt(b[0]+ "" + a[0]);
		System.out.println(Math.min(i1, i2));
	}
}