import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class program {

	public static void main(String[] args) throws Throwable {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int m = in.nextInt();
		int a[] = new int[n];
		int b[] = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		boolean mn=false;
		ArrayList<Integer> res=new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(a[i]==b[j]){
					mn=true;
					res.add(a[i]);
					
				}
			}
		}
		int mina=0;
		if(!res.isEmpty()){
			 mina=Collections.min(res);
		}
		
		if(mn){
			out.print(mina);
		}else{
			int min1=a[0];
			int min2=b[0];
			for (int i = 0; i < n; i++) {
				if(a[i]<min1)min1=a[i];
			}
			for (int i = 0; i < m; i++) {
				if(b[i]<min2)min2=b[i];
			}
			String ans="";
			if(min1>min2)
				ans=min2+""+min1+"";
			else if(min1<min2)
				ans=min1+""+min2+"";
			else if(min1==min2)
				ans=min1+"";
			out.println(ans);
		}
		
		
		
		out.flush();
		out.close();

	}

}
