var  amountLine=readline();
var  Number1=readline();
var  Number2=readline();
var  amount = amountLine.split(" ").map(Number);
var  Number1Array = Number1.split(" ").map(Number);
var  Number2Array = Number2.split(" ").map(Number);
Number1Array.sort(function(a, b){return a - b});
Number2Array.sort(function(a, b){return a - b});
var result=0;
var commonarr=Number1Array.filter(value => -1 !== Number2Array.indexOf(value));
function getResult() {
  if(commonarr.length>1) {
	result=commonarr[0];
	return result
}
if(Number1Array[0]>Number2Array[0]) {
    result=parseInt(Number2Array[0]+''+Number1Array[0]);
  	return result
}
if(Number1Array[0]<Number2Array[0]) {
    result=parseInt(Number1Array[0]+''+Number2Array[0]);
  	return result
}
}
print(getResult());