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

public class A1008 {
    public static void main(String [] args) {
        InputStream inputReader = System.in;
        OutputStream outputReader = System.out;
        InputReader in = new InputReader(inputReader);
        PrintWriter out = new PrintWriter(outputReader);
        Algorithm solver = new Algorithm();
        solver.solve(in, out);
        out.close();
    }
}

class Algorithm {
    void solve(InputReader ir, PrintWriter pw) {

        int n = ir.nextInt(), m = ir.nextInt(), num1 = 0, num2 = 0;
        int [] array = new int[10];

        for (int i = 0; i < n; i++) array[ir.nextInt()]++;
        for (int i = 0; i < m; i++) array[ir.nextInt()] += 2;

        for (int i = 1, count1 = 0, count2 = 0; i < 10; i++) {
            if (array[i] == 1 && count1 == 0) {
                num1 = i;
                count1 = 1;
            } else if (array[i] == 2 && count2 == 0) {
                num2 = i;
                count2 = 1;
            }
        }

        if (num1 == 0 || num2 == 0) {
            for (int i = 1; i < 10; i++) {
                if (array[i] == 3) {
                    pw.print(i);
                    break;
                }
            }
        } else {
            if (num1 < num2) {
                pw.print(array[num1] != 1 ? "" : num1);
                pw.print(array[num2] != 2 ? "" : num2);
            } else {
                pw.print(array[num2] != 2 ? "" : num2);
                pw.print(array[num1] != 1 ? "" : num1);
            }
        }


    }

    private static void Qsort(int[] array, int low, int high) {

        int i = low;
        int j = high;
        int x = array[low + (high - low) / 2];

        do {
            while (array[i] < x) ++i;
            while (array[j] > x) --j;
            if (i <= j) {
                int tmp = array[i];
                array[i] = array[j];
                array[j] = tmp;
                i++;
                j--;
            }
        } while (i <= j);

        if (low < j) Qsort(array, low, j);
        if (i < high) Qsort(array, i, high);

    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

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

    String nextLine(){
        String fullLine = null;
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                fullLine = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return fullLine;
        }
        return fullLine;
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
    long nextLong() {
        return Long.parseLong(next());
    }

}