import java.util.*;

public class Test2 {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),m=scan.nextInt(),o=10;
		int[] a=new int[n],b=new int[m];
		for (int i=0;i<n;i++){
			a[i]=scan.nextInt();
		}
		for (int i=0;i<m;i++){
			b[i]=scan.nextInt();
		}
		n=a[0];
		m=b[0];
		scan.close();
		for (int i:a)for (int j:b){
			n=Math.min(i, n);
			m=Math.min(j, m);
			if (i==j)o=Math.min(o, i);
		}
		if (o==10){
			System.out.print(Math.min(n, m));
			System.out.print(Math.max(n, m));
		}else System.out.print(o);
	}

}