import java.lang.reflect.Array;
import java.util.*;

public class Main {

    static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer> a = new ArrayList<>(n);
        List<Integer> b = new ArrayList<>(m);
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            b.add(sc.nextInt());
        }
        Collections.sort(a);
        Collections.sort(b);
        int minA = a.get(0);
        int minB = b.get(0);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(a.get(i) == b.get(j)){
                    System.out.print(a.get(i));
                    return;
                }
            }
        }
        int val = minA<minB ? 10*minA+minB : 10*minB+minA;
        System.out.print(val);
    }

    public static void main(String[] args) {
        solve();


    }
}
