import java.util.Scanner;
public class search {
public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int m = scan.nextInt();
	int minn = 10;
	int minm = 10;
	int p;
	for(int i=0;i<n;i++){
		p=scan.nextInt();
		if(p<minn){
			minn=p;
		};
	}
	for(int i=0;i<m;i++){
		p=scan.nextInt();
		if(p<minm){
			minm=p;
		};
	};
	int answ;
	if (minn==minm){
		answ=minn;
	}else if(minm*10+minn<minn*10+minm){
		answ=minm*10+minn;
	}else{
		answ=minn*10+minm;
	};
	System.out.println(answ);
}
}
