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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        List<Integer> a = new ArrayList<>();
        List<Integer> b = new ArrayList<>();
        Integer result = null;

        int m = in.nextInt();
        int n = in.nextInt();
        in.nextLine();
        for (int i =0;i<m; i++) {
            a.add(in.nextInt());
        }
        in.nextLine();
        for (int i =0;i<n; i++) {
            int t = in.nextInt();
            if (a.contains(t)) {
                if(null != result) {
                     if(result > t) {
                         result = t;
                     }
                } else {
                    result = t;
                }
            }
            b.add(t);
        }
        Collections.sort(a);
        Collections.sort(b);
        int a1 = a.get(0);
        int b1 = b.get(0);

        int r1 = Integer.valueOf(a1 + "" + b1);
        int r2 = Integer.valueOf(b1 + "" + a1);

        int early;
        if(a1==b1) {
            early=a1;
        } else {
            if (r1 > r2) {
                early = r2;
            } else {
                early = r1;
            }
        }
        if (null != result) {
            if (result < early) {
                out.println(result);
            } else {
                out.println(early);
            }
        } else {
            out.println(early);
        }

        out.flush();
    }
}