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


public class Main {

    static StringBuilder data = new StringBuilder();
    final static FastReader in = new FastReader();


    public static void main(String[] args) {
        int n = in.nextInt(), m = in.nextInt(),t;
int a[] = new int[10];
        int f = 10, s = 10;
        for (int i = 0; i < n; i++) {
           t=in.nextInt();
           f=Math.min(t,f);
           if(a[t]==0){
               a[t]++;
           }

        }
        for (int i = 0; i < m; i++) {
            t=in.nextInt();
            s=Math.min(t,s);
            if(a[t]<2){
                a[t]++;
            }


        }
        int g=0;
        for (int i = 0; i < a.length; i++) {
            if(a[i]==2){
                g=a[i];
                break;
            }
        }
        if(g>0){
            System.out.println(g);
        }else{
            System.out.println(Math.min(f,s)+""+ Math.max(f,s));
        }


    }


    static void fileOut(String s) {
        File out = new File("output.txt");
        try {
            FileWriter fw = new FileWriter(out);
            fw.write(s);
            fw.flush();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        public FastReader(String path) {
            try {
                br = new BufferedReader(new
                        InputStreamReader(new FileInputStream(path)));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }


        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}