import java.util.*;

public class SearchPrettyInteger{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        ArrayList<Integer> set1 = new ArrayList();
        ArrayList<Integer> set2 = new ArrayList();
        for(int i = 0; i< n; i++){
            set1.add(sc.nextInt());
        }
        for(int i = 0; i < m; i++){
            set2.add(sc.nextInt());
        }
        Collections.sort(set1); Collections.sort(set2);
        //common digit
        int a = -1, b = -1;
        for(int i = 0; i < n; i++){
            if(set2.contains(set1.get(i))){
                a = set1.get(i);
                break;
            }
        }
        for(int i = 0; i < m; i++){
            if(set1.contains(set2.get(i))){
                a = set2.get(i);
                break;
            }
        }
        if(a == -1 && b == -1){
            a = set1.get(0); b = set2.get(0);
            System.out.println(Math.min(a, b) * 10 + Math.max(a, b));
            return;
        }
        if(a == -1){
            System.out.println(b); return;
        }
        System.out.println(a); return;
    }
}