import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {

    static class TaskG {

        private void solve(int test, FastScanner in, PrintWriter out) {
            int n = in.nextInt(),m = in.nextInt();
            int[] a = new int[10],b = new int[10];
            for (int i = 0; i < n; i++) {
                int k = in.nextInt();
                a[k]=1;
            }
            for (int i = 0; i < m; i++) {
                int k=in.nextInt();
                b[k]=1;
            }
            int m1=0,m2=0;
            for (int i = 1; i < 10; i++) {
                if (a[i] == 1 && b[i] == 1) {
                    out.println(i);
                    return;
                }
                if (m1 == 0 && a[i] == 1) {
                    m1 = i;
                }
                if (m2 == 0 && b[i] == 1) {
                    m2 = i;
                }
            }
            if (m1<m2){
                out.print(m1);
                out.println(m2);
            }
            if (m1>=m2){
                out.print(m2);
                out.println(m1);
            }

        }
    }

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        FastScanner in = new FastScanner("file");
//        PrintWriter out = new PrintWriter(new FileWriter("file"));
        new TaskG().solve(1, in, out);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer token;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return token.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}