import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
	
		//input
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int min1 = 9;
		int min2 = 9;
		
		int buf1;
		int buf2;
		
		for(int i1 = 1; i1<=n; i1++) {
			buf1 = in.nextInt();
			if(buf1 < min1) {
				min1 = buf1;
			}
		}
		
		
		
		for(int i2 = 1; i2<=m; i2++) {
			buf2 = in.nextInt();
			if(buf2 < min2) {
				min2 = buf2;
			}
		}
		
		//System.out.println(min2);
		
		if(min1 < min2) {
			System.out.println((min1*10)+ min2);
		} else if(min1 > min2) {
			System.out.println((min2*10)+ min1);
		} else {
			System.out.println(min1);
		}
		
	}
}
