/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codeforces870A
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int min1=Integer.MAX_VALUE;
		int min2=Integer.MAX_VALUE;
		int[] a=new int[10];
		int[] b=new int[10];
		for(int i=0;i<n;i++)
		{
		
		int t=sc.nextInt();
		if(min1>t){
			min1=t;
			
		}
		
		a[t]++;
		}
		for(int i=0;i<m;i++){
			int t=sc.nextInt();
			b[t]++;
				if(min2>t){
				min2=t;
				}
			
		}
		
		int ans=0;
		
		for(int i=0;i<9;i++){
			if(a[i]>0&&b[i]>0){
				ans=i;
				break;
			}
		}
		
		if(ans!=0){
			System.out.println(ans);
		}
		else{
			if(min1<min2){
			System.out.print(min1+""+min2);
			}
			else{
			System.out.print(min2+""+min1);	
			}
			System.out.println();
		}
		
		
		
		
		
		
		
	}
}
