import java.util.*;
import java.io.*;

public class p870A {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		int[] a = new int[Integer.parseInt(st.nextToken())];
		int[] b = new int[Integer.parseInt(st.nextToken())];
		load(a, f.readLine());
		load(b, f.readLine());
		
		Arrays.sort(a);
		Arrays.sort(b);
		
		for(int i = 0; i < a.length; i++)
			if(contains(b, a[i]))
			{
				System.out.println(a[i]);
				return;
			}
		int d1 = a[0];
		int d2 = b[0];
		if(d1 <= d2)
			System.out.println("" + d1 + d2);
		else
			System.out.println("" + d2 + d1);
	}
	
	public static boolean contains(int[] a, int num)
	{
		for(int i =0; i < a.length; i++)
		{
			if(a[i] == num)
				return true;
			if(a[i] > num)
				return false;
		}
		return false;
	}
	
	public static void load(int[] a, String s)
	{
		StringTokenizer st = new StringTokenizer(s);
		for(int i =0 ; i < a.length; i++)
			a[i] = Integer.parseInt(st.nextToken());
	}
}