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

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();	
		int m =in.nextInt();
		int min1 =10;
		int min2 = 10;
		for(int i=0;i<n;i++){
			int k =in.nextInt();
			if(k<min1){
				min1=k;
			}
		}
		for(int i=0;i<m;i++){
			int k =in.nextInt();
			if(k<min2){
				min2=k;
			}
		}
		int min = Math.min(min1, min2);
		int max = Math.max(min1, min2);
		if(min == max){
			out.println(min);
		}else{
			out.println(min+""+ max);
		}
		out.close();
	}
}
