import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Solution
{

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

        int n = in.nextInt() ,
                m = in.nextInt() ,
                a[] = new int[n] ,
                b[] = new int[m] ,
                min = 9 , index , res;

        for(int i = 0;i < n;i++)
        {
            a[i] = in.nextInt();
        }

        for(int i = 0;i < n;i++)
        {
            b[i] = in.nextInt();
            index = Arrays.binarySearch(a , b[i]);
            if(index > -1 && b[i] < min)
            {
                min = b[i];
            }
        }

        if(min == 9)
        {
            int mina = min(a) , minb = min(b);
            res = Math.min(mina , minb)*10 + Math.max(mina , minb);
        }
        else
        {
            res = min;
        }

        out.println(res);
        out.close();
    }

    public static int min(int[] a)
    {
        int min = 10;
        for(int i = 0;i < a.length;i++)
        {
            if(a[i] < min)
            {
                min = a[i];
            }
        }
        return min;
    }

    static class Reader
    {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public Reader(InputStream in)
        {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try
                {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch(IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }

}