import java.util.*;

 // Compiler version JDK 11.0.2

public class Dcoder
 {
   public static void main(String args[])
   { 
    Scanner sc=new Scanner(System.in);
    List<Integer> l=new ArrayList<>();
    List<Integer> l1=new ArrayList<>();
    int n=sc.nextInt();
    int m=sc.nextInt();
    while(n-- > 0){
      l. add(sc.nextInt());
    }
    while(m-- > 0){
      l1. add(sc.nextInt());
    }
    Collections. sort(l);
    Collections. sort(l1);
   
if(l.get(0) == l1. get(0)){
  System. out. println(l.get(0));
}else{
  System. out. println(l.get(0)+""+l1.get(0));
}
   }
 }
    