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;
if(Number1Array[0]==Number2Array[0]) {
	result=Number1Array[0]
}
else  {
	result==Number(Number1Array[0]+''+Number2Array[0]);
}
print(result);