import java.io.PrintWriter;
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();
		}
		int min1=100;
		int min2=100;
		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();

	}

}
