import java.util.Scanner;
import java.io.PrintWriter;
import java.util.TreeSet;

public class Task870A
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();

        TreeSet<Integer> set1 = new TreeSet<Integer>();
        for(int i = 0; i < n; ++i)
        {
            set1.add(in.nextInt());
        }
        TreeSet<Integer> set2 = new TreeSet<Integer>();
        for(int i = 0; i < m; ++i)
        {
            set2.add(in.nextInt());
        }

        boolean foundSame = false;
        for(Integer i : set1)
        {
            if(set2.contains(i))
            {
                out.println(i);
                foundSame = true;
                break;
            }
        }
        if(!foundSame)
        {
            out.println("" + set1.first() + set2.first());
        }

        out.close();
    }
}
