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

public class Main {
    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens())
                tokin = new StringTokenizer(in.readLine());
            return tokin.nextToken();
        }

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

    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    static class Couple {
        long x;
        boolean orient;

        Couple(long x1, boolean a) {
            x = x1;
            orient = a;
        }
    }

    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int n = in.nextInt();
        int m = in.nextInt();
        int minn = 99999999;
        int minm = 99999;
        int arr[] = new int[n];
        int h = 999999;
        for (int i = 0; i < n; i++) {
            int c = in.nextInt();
            arr[i] = c;
            if(c < minn)
                minn = c;
        }
        for (int i = 0; i < m; i++) {
            int c = in.nextInt();
            if(c < minm)
                minm = c;
            for (int j = 0; j < n; j++) {
                if(arr[j] == c && c < h)
                    h = c;
            }
        }
        if(h == 999999){
            if(minn < minm){
                out.print(minn);
                out.print(minm);
            } else {
                out.print(minm);
                out.print(minn);
            }
        } else {
            out.print(h);
        }
        out.close();
    }
}