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

public class O2_A {
	FastScanner in;
	PrintWriter out;

	public void solve() {
		boolean one[] = new boolean[10];
		boolean two[] = new boolean[10];
		int n = in.nextInt();
		int m = in.nextInt();
		for (int i = 0; i < n; i++) {
			one[in.nextInt()] = true;
		}
		for (int i = 0; i < m; i++) {
			two[in.nextInt()] = true;
		}
		
		for (int i = 1; i < 10; i++) {
			if (one[i]&&two[i]) {
				out.println(i);
				return;
			}
		}
		int f = -1;
		int s = -1;
		for (int i = 0; i < 10; i++) {
			if (one[i]) {
				f = i;
				break;
			}
		}
		for (int i = 0; i < 10; i++) {
			if (two[i]) {
				s = i;
				break;
			}
		}
		out.println(Math.min(f, s) +""+Math.max(f, s));
	}

	public void run() {
		in = new FastScanner();
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		solve();
		out.close();
	}

	class FastScanner {
		StringTokenizer st;
		BufferedReader br;

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				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());
		}

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

	public static void main(String[] args) {
		new O2_A().run();
	}
}
