import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;



public class Main {

    public static void main(String[] args) {
        FastReader fr =new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int n = fr.nextInt() , m = fr.nextInt();
        int[] a = new int[n] , b = new int[m];
        boolean[] c = new boolean[10];

        for (int i = 0; i < n; i ++) {
            a[i] = fr.nextInt();
            c[a[i]] = true;
        }
        for (int i = 0; i < m; i ++) {
            b[i] = fr.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        for (int i = 0; i < m; i ++) {
            if (c[b[i]]) {
                out.print(b[i]);
                out.close();
                return;
            }
        }
        out.print(Math.min(a[0],b[0])+ "" + Math.max(a[0],b[0]));
        out.close();
    }






    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
