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


public class alpha {
    String filename = "subseq";//filename here, System.in/out if no file

    FastScanner in;
    PrintWriter out;

    void solve() {
        PriorityQueue<Integer> a=new PriorityQueue<>();
        PriorityQueue<Integer> b=new PriorityQueue<>();
        PriorityQueue<Integer> both=new PriorityQueue<>();
        int x=in.nextInt();
        int y=in.nextInt();
        for (int i=0; i<x;i++) a.add(in.nextInt());
        for (int i=0; i<y;i++) {
            int k=in.nextInt();
            b.add(k);
            if (a.contains(k)) both.add(k);
        }
        if (!both.isEmpty())
        out.println(both.peek());
        else {
            int r=a.peek();
            int t=b.peek();
            out.println(Math.min(r,t)+""+Math.max(r,t));
        }
    }

    void run() throws IOException {
        InputStream input = System.in;
        OutputStream output = System.out;
        try {
            File f = new File(filename + ".in");
            if (f.exists() && f.canRead()) {
                input = new FileInputStream(f);
                output = new FileOutputStream(filename + ".out");
            }
        } catch (IOException e) {
        }
        in = new FastScanner(input);
        out = new PrintWriter(new BufferedOutputStream(output));
        solve();
        in.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new alpha().run();
    }

    class FastScanner implements Closeable {
        private BufferedReader br;
        private StringTokenizer tokenizer;

        public FastScanner(InputStream stream) throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(stream));
        }

        public boolean hasNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    String s = br.readLine();
                    if (s == null) {
                        return false;
                    }
                    tokenizer = new StringTokenizer(s);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.hasMoreTokens();
        }

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

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

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

        @Override
        public void close() throws IOException {
            br.close();
        }
    }
}