import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Driver {

	public static Scanner scanner;
	public static void main(String[] args) {
		scanner = new Scanner(System.in);
	
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		List<Integer> first = new ArrayList<>();
		List<Integer> second = new ArrayList<>();
		int firstMin = Integer.MAX_VALUE;
		int secondMin = Integer.MAX_VALUE;
		for(int i=0; i<n; i++) {
			first.add(scanner.nextInt());
			firstMin = Math.min(firstMin, first.get(i));
		}
		for(int i=0; i<m; i++) {
			second.add(scanner.nextInt());
			secondMin = Math.min(secondMin, second.get(i));
		}
		
		int combMin = Math.min(firstMin, secondMin);
		if(firstMin==secondMin) {
			System.out.println(firstMin);
			return;
		}
		if(firstMin<secondMin) {
			System.out.println(firstMin+ "" + secondMin);
		}else if (secondMin<firstMin) {
			System.out.println(secondMin+ "" + firstMin);
		}
		
		
		
	}

}




















