import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
public class codeforces870A
{ 
	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; 
		} 
	} 

	public static void main(String[] args) 
	{ 
        FastReader s=new FastReader();
        StringBuilder sb=new StringBuilder();
        int n=s.nextInt(),m=s.nextInt(),i,x,y;
        List<Integer> l1= new LinkedList<>();
        List<Integer> l2= new LinkedList<>();
        List<Integer> l3= new LinkedList<>();
        for(i=0;i<n;i++)
        l1.add(s.nextInt());
        for(i=0;i<m;i++)
        l2.add(s.nextInt());
        for(i=0;i<m;i++)
        {
            if(l1.contains(l2.get(i)))
            l3.add(l2.get(i));
        }
        if(l3.isEmpty())
        {
            x=Collections.min(l1);
            y=Collections.min(l2);
            sb.append(Math.min(x,y));
            sb.append(Math.max(x,y));
        }
        else
        sb.append(Collections.min(l3));
        System.out.print(sb);
    }
}