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

public class Solution {


    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    public static void main(String[] args) {
        new Solution().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    void init() throws FileNotFoundException {

        if (true) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }

        tok = new StringTokenizer("");
    }

    void run() {
        try {
            long timeStart = System.currentTimeMillis();

            init();
            solve();

            out.close();

            long timeEnd = System.currentTimeMillis();
            System.err.println("Time = " + (timeEnd - timeStart));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    String readLine() throws IOException {
        return in.readLine();
    }


    String delimiter = " ";

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    void solve() throws IOException {
        int n = readInt();
        int m = readInt();
        int[] na = new int[n];
        int[] ma = new int[m];
        int[] oa = new int[10];
        int nlo = 10;
        int mlo = 10;
        int olo = 10;
        boolean ol = false;
        for(int i = 0; i < n; i++)
        {
            na[i] = readInt();
            if(na[i] < nlo)
            {
                nlo = na[i];
            }
        }
        for(int i = 0; i < m; i++)
        {
            ma[i] = readInt();
            if(ma[i] < mlo)
            {
                mlo = ma[i];
            }
        }
        for(int i = 0; i < n; i++)
        {
            for(int g = 0; g < m; g++)
            {
                if(na[i] == ma[g] && na[i] < olo)
                {
                   olo = na[i];
                   ol = true;
                }
            }
        }
        if(ol)
        {
            out.println(olo);
        }
        else if(nlo < mlo)
        {
            out.print(nlo);
            out.print(mlo);
        }
        else if(mlo < nlo)
        {
            out.print(mlo);
            out.print(nlo);
        }

    }
}