import java.util.Scanner;

public class JavaApplication16 {

public static void main(String[] args) { 

Scanner sc = new Scanner(System.in); 

int a=sc.nextInt(); 
int b=sc.nextInt(); 
if(a!=0&&b!=0&& a<=10&&b<=10) {
int []a1= new int[a]; 
int []b1= new int[b]; 
int j=10; 
int j1=10; 
int c=0; 
int i1;
boolean x=false;
for(int i=0;i<a1.length;i++){ 
a1[i]=sc.nextInt(); 
} 
for(int i=0;i<b1.length;i++){ 
b1[i]=sc.nextInt(); 
} 
for (int i=0; i<a1.length; i++){
    if(x==false){
    for (i1=0; i1<b1.length; i1++){
    if (a1[i]==b1[i1]) {x=true; c=b1[i1];}
    
    }
}
    
    
}
if (x==true)System.out.print(c); 
else{
for(int i=0;i<a1.length;i++){ 
if(a1[i]<j){ j=a1[i];} 
} 

for(int i=0;i<b1.length;i++){ 
if(b1[i]<j1){ j1=b1[i];} 
} 

if(j!=0&&j1!=0 && j<=10 && j1<=10) {
if(j==j1){ 
System.out.println(j); 
} 
else{ 
if(j<j1){ 
c=j*10+j1; 
} 
if(j1<j){ 
c=j1*10+j; 
} 


System.out.print(c); 
} }


} 
}
}}