
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int a[] = new int[n];
		int amin=10;
		int b[] = new int[m];
		int bmin=10;
		boolean f = false;
		int c = 10;
		for(int i = 0 ; i < n ; i++) {
			a[i] = in.nextInt();
			if(a[i]<amin) amin = a[i];
		}
		for(int i = 0 ; i < m ; i++) {
			b[i] = in.nextInt();
			if(b[i]<bmin) bmin = b[i];
			for(int j = 0 ; j < n ; j++ ) {
				if(b[i] == a[j] && a[j] < c) {
					f = true;
					c = a[j];
				}
			}
		}
		if(f) {
			System.out.println(c);
		}else {
			if(amin>bmin) System.out.println(bmin+""+amin);
			else if(amin<bmin) System.out.println(amin+""+bmin);
			else System.out.println(amin);
		}
		in.close();
	}

}

 		  		   	   			 		   	 	 			