import java.util.*;
public class codeforces870A
{ 
	public static void main(String[] args) 
	{ 
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
        int n=s.nextInt(),m=s.nextInt(),i,x,y;
        List<Integer> l1= new LinkedList<>();
        List<Integer> l2= new LinkedList<>();
        List<Integer> l3= new LinkedList<>();
        for(i=0;i<n;i++)
        l1.add(s.nextInt());
        for(i=0;i<m;i++)
        l2.add(s.nextInt());
        for(i=0;i<m;i++)
        {
            if(l1.contains(l2.get(i)))
            l3.add(l2.get(i));
        }
        if(l3.isEmpty())
        {
            x=Collections.min(l1);
            y=Collections.min(l2);
            sb.append(Math.min(x,y));
            sb.append(Math.max(x,y));
        }
        else
        sb.append(Collections.min(l3));
        System.out.print(sb);
    }
}