import java.util.Scanner;


public class SearchForPrettyIntegers {
	private int m;
	private int n;
	private char [] a;
	private char [] b;
	private Scanner sc;
	
	public SearchForPrettyIntegers(){
		sc=new Scanner(System.in);
		do{
			
			
			n=sc.nextInt();
			
			m=sc.nextInt();
			a=new char [n];
			b=new char [m];
			for(int i=0; i<n; i++){
				do{
					
					a[i]=sc.next().charAt(0);
				}while(a[i]<'1' || a[i]>'9');
			}
			for(int i=0; i<m; i++){
				do{
					
					b[i]=sc.next().charAt(0);
				}while(b[i]<'1' || b[i]>'9');
			}
		}while(m==0 || n==0);
	}

	private char min(char a, char b){
		return (a<b)? a:b;
	}
	
	private char max(char a, char b){
		return (a>b)? a:b;
	}
	
	public int whatIsPI(){
		char firstDigit=0;
		char secondDigit = 0;
		char min1=a[0];
		char min2=b[0];
		String ch="";
		if(a.length==1){
			ch=String.valueOf(a[0]);
			return Integer.parseInt(ch);
		}
		else
			if(b.length==1){
				ch=String.valueOf(b[0]);
				return Integer.parseInt(ch);
			}
		for(int i=0; i<n; i++){
			firstDigit=(min(a[i],min1));
		}
		
		for(int i=0; i<m; i++){
			secondDigit=min(b[i],min2);
		}
		
		
		if(firstDigit!=secondDigit){
		ch+=(String.valueOf(min(firstDigit,secondDigit)));
		ch+=(String.valueOf(max(firstDigit,secondDigit)));
		}
		else
			ch=String.valueOf(firstDigit);
		ch+="";
		
		return Integer.parseInt(ch);	
	}
	
	public static void main(String[] args) {
		SearchForPrettyIntegers s=new SearchForPrettyIntegers();
		System.out.println(s.whatIsPI());
	}
}
