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

public class NewMain_1 {

    public static void main(String[] args) {
        // TODO code application logic here
        FastReader s = new FastReader();
        int a = s.nextInt();
        int b = s.nextInt();
        int[] arA = new int[10];
        int[] arB = new int[10];
        int smA = Integer.MAX_VALUE, smB = Integer.MAX_VALUE;
        for (int i = 0; i < a; i++) {
            int x = s.nextInt();
            arA[x]++;
            smA = Math.min(smA, x);
        }
        for (int i = 0; i < b; i++) {
            int x = s.nextInt();
            arB[x]++;
            smB = Math.min(smB, x);
        }

        int sm = Integer.MAX_VALUE;
        for (int i = 1; i < 10; i++) {
            if (arA[i] == arB[i]) {
                System.out.println(i);
                return;
            }
        }

        if (smA < smB) {
            System.out.println(smA + "" + smB);
        } else {
            System.out.println(smB + "" + smA);
        }

    }

    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;
        }
    }
}
