import java.io.*;
import java.util.*;
public class Lo 
{
   
    public static void main(String args[] ) throws Exception 
    {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        int min1=Integer.MAX_VALUE;
        int min2=Integer.MAX_VALUE;
        for(int i=0;i<n;i++)
        {
            a[i] = in.nextInt();
            if(a[i]<min1)
            {
                min1 = a[i];
            }

        }
        for(int i=0;i<m;i++)
        {
            b[i] = in.nextInt();
            if(b[i]<min2)
            {
                min2 = b[i];
            }
        }

        if(min1==min2)
        {
            System.out.println(min1);
        }
        else if(min1<min2)
        {
            System.out.print(min1+""+min2);
        }
        else if(min1>min2)
        {
            System.out.print(min2+""+min1);
        }

        


    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


