import java.io.BufferedReader;
import java.io.PrintWriter;

import java.io.InputStreamReader;

import java.io.IOException;

import java.util.StringTokenizer;

public class Main {
    
    static Scanner in = new Scanner();
    static PrintWriter out = new PrintWriter(System.out);
    
    public static void main(String[] args) throws IOException {
        int[] min = {10, 10}, n = {in.nextInt(), in.nextInt()};
        boolean b[][] = new boolean[2][10];
        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < n[i]; j++) {
                int k = in.nextInt();
                min[i] = Math.min(k, min[i]);
                b[i][k] = true;
            }
        }
        for(int i = 1; i < 10; i++)
            if(b[0][i] && b[1][i]) {
                out.print(i);
                out.close();
                return;
            }
        out.print(Math.min(min[0], min[1]) + "" + Math.max(min[0], min[1]));
        out.close();
    }
    
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;
        
        public Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        }
        
        public String next() throws IOException {
            if(!st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}