import java.io.*;
import java.util.*;
public class Tmr2
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer datos=new StringTokenizer(in.readLine());
        int a=Integer.parseInt(datos.nextToken());
        int b=Integer.parseInt(datos.nextToken());
        StringTokenizer s1=new StringTokenizer(in.readLine());
        StringTokenizer s2=new StringTokenizer(in.readLine());
        int menor1=Integer.parseInt(s1.nextToken());
        int menor2=Integer.parseInt(s2.nextToken());
        int i;
        for(i=1;i<a;i++)
        {
            int aux2=Integer.parseInt(s1.nextToken());
            if(menor1>aux2)
                menor1=aux2;
        }
        if(s2.equals("9"))
        {
            System.out.println(menor1);
        }
        else
        {
            for(i=1;i<b;i++)
        {
            int aux2=Integer.parseInt(s2.nextToken());
            if(menor2>aux2)
                menor2=aux2;
        }
        if(menor1==menor2)
            System.out.println(menor1);
        else if(menor1<menor2)
            System.out.println(menor1+""+menor2);
        else
            System.out.println(menor2+""+menor1);
        }
    }
}