import java.io.*;
import java.util.*;
import java.math.*;

public class Competitive_1 {
	
	public static void main(String[] args) {
		FastReader in = new FastReader();
		int n=in.nextInt(), m=in.nextInt();
		int d1=Integer.MAX_VALUE, d2=Integer.MAX_VALUE;
		
		HashSet<Integer> s1=new HashSet<Integer>();
		
		for(int i=0; i<n; i++){
			int x = in.nextInt();
			d1 = d1>x ? x : d1;
			s1.add(x);
		}
		
		boolean flag = false;
		for(int i=0; i<m; i++){
			int x = in.nextInt();
			d2 = d2>x ? x : d2;
			
			if(s1.contains(x)){
				flag = true;
			}
		}
		
		if(flag){
			System.out.println(d2);
			return;
		}
		
		if(d1<d2)
			System.out.println(d1+""+d2);
		else if(d1>d2)
			System.out.println(d2+""+d1);

	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	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;
        }
    }
	
}