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


public class TexCup2_A {
    FastScanner in;
    PrintWriter out;

    public static void main(String[] arg) {
        new TexCup2_A().run();
    }


    public void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int a = Integer.MAX_VALUE;
        int b = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            a = Math.min(a, in.nextInt());
        }
        for (int i = 0; i < m; i++) {
            b = Math.min(b, in.nextInt());
        }
        if (a == b) {
            out.print(a);
            return;
        }
        out.print(Math.min(a, b) +"" + Math.max(a, b));
    }
    public void run() {
        try {
            in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(BufferedReader bufferedReader) {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

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

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

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



    }
}
