import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class PrettyIntegers{

	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		int numberOfFirst = scanner.nextInt();
		int numberoFSecond = scanner.nextInt();

		List<Integer> firstArray = new ArrayList<Integer>();
		List<Integer> secondArray = new ArrayList<Integer>();

		int uniqueOfFirst = 0;
		int uniqueOfSecond = 0;

		for(int i=0; i<numberOfFirst; i++){
			int value = scanner.nextInt();

			if(firstArray.indexOf(value) == -1) uniqueOfFirst++;

			firstArray.add(value);
		}

		for(int i=0; i<numberoFSecond; i++){
			int value = scanner.nextInt();

			if(secondArray.indexOf(value) == -1) uniqueOfSecond++;
			
			secondArray.add(value);
		}

		Collections.sort(firstArray);
		Collections.sort(secondArray);

		if(uniqueOfFirst >= 8 && uniqueOfSecond >= 8){	
			System.out.println("1");			
		}else if(uniqueOfFirst >= 8 && uniqueOfSecond < 8){
			System.out.println(secondArray.get(0));						
		}else{
			int lower = firstArray.get(0);
			int greater = secondArray.get(0);
			int temp;

			if(lower > greater){
				temp = greater;
				greater = lower;
				lower = temp;
			}

			System.out.println(lower+""+greater);
		}

	}

}