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 a = 9;
		int b = 9;
		int c = 9;
		int[] first = new int[n];
		int[] second = new int[m];
		for(int i=0;i<n;i++) {
			first[i]=sc.nextInt();
			if(first[i]<=b) {
				b=first[i];
			}
		}
		for(int i=0;i<m;i++) {
			second[i]=sc.nextInt();
			if(second[i]<=c) {
				c=second[i];
			}
		}
		for(int i=0;i<n;i++) {
			for(int l=0;l<m;l++) {
				if(first[i]==second[l]) {
					if(first[i]<=a) {
						a=first[i];
						b=first[i];
						c=first[i];
					}
				}
			}
		}
	if(b==c) {
		System.out.println(b);
		System.exit(0);
	}
		if(b<c) {
			System.out.println(b+""+c);
		}else {
			System.out.println(c+""+b);
		}
	}

}
