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

public class CF870A {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), m = scan.nextInt();
		int[] a = new int[n];
		int[] b = new int[m];
		for(int i = 0 ; i < n ; i++)
			a[i] = scan.nextInt();
		for(int j = 0 ; j < m ; j++)
			b[j] = scan.nextInt();
		int dup = Integer.MAX_VALUE;
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < m ; j++)
				if(a[i] == b[j])
					dup = Math.min(dup, a[i]);
		if(dup != Integer.MAX_VALUE) {
			System.out.println(dup);
			return;
		}
		int min = Integer.MAX_VALUE;
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < m ; j++)
				min = Math.min(min, Math.min(a[i]*10+b[j], b[j]*10+a[i])); 
		System.out.println(min);
	}
}
