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

/**
 * 870A
 * θ(10) time
 * θ(10) space
 *
 * @author artyom
 */
public class _870A implements Runnable {
    private BufferedReader in;
    private StringTokenizer tok;

    private Object solve() throws IOException {
        int n = nextInt(), m = nextInt();
        boolean[] a = readArray(n), b = readArray(m);
        int minA = -1, minB = -1;
        for (int i = 0; i < 9; i++) {
            if (a[i] && b[i]) {
                return i;
            }
            if (a[i] && minA == -1) {
                minA = i;
            }
            if (b[i] && minB == -1) {
                minB = i;
            }
        }
        return minA < minB ? minA + "" + minB : minB + "" + minA;
    }

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

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            System.out.print(solve());
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    private String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

    private boolean[] readArray(int n) throws IOException {
        boolean[] arr = new boolean[10];
        for (int i = 0; i < n; i++) {
            arr[nextInt()] = true;
        }
        return arr;
    }
}