import java.util.*;

public class helloWorld 
{
	public static void main(String[] args) 
	{		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[10];
		int ans = 0;
		
		for(int i = 0; i < n; i++)
			ar[ in.nextInt() ]++;
		for(int i = 0; i < m; i++)
			ar[ in.nextInt() ] += 2;
		
		for(int i = 1; i <= 9; i++)
			if(ar[i] == 3) {
				ans = i;
				break;
			}
		if(ans == 0) {
			for(int i = 1; i <= 9; i++)
				if(ar[i] == 1) {
					ans = 10 * i;
					break;
				}
			for(int i = 1; i <= 9; i++)
				if(ar[i] == 2) {
					ans += i;
					break;
				}
		}
		
		System.out.println(ans);
		
		in.close();
	}
}
