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

public class Main {
    public static boolean[] seen;
    public static int ceiling (int a, int b) {
        int n = (a + b - 1) / b;
        return n;
    }
    public static void dfs(ArrayList[] graph, int v) {
        if (seen[v]) {
            return;
        }
        seen[v] = true;
        for (int i = 0; i < graph[v].size(); i++) {
            int w = (int)graph[v].get(i);
            dfs(graph,w);
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for (int j = 0; j < m; j++) {
            b[j] = in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i]==b[j]) {
                    out.println(a[i]);
                    out.flush();
                    return;
                }
            }
        }
        out.println(Math.min(a[0]*10+b[0] , b[0]*10+a[0]));

        out.flush();
    }
}