import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
public class Main {

public static void main(String[] args) {
    //solution start :-)
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n];
		int b[] = new int[m];
		int frea[] = new int[10];
		int freb[] = new int[10];
		int min1 = 15;
		int min2 = 15;
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			if(min1>a[i]) min1 = a[i];
			frea[a[i]]++;
		}
		for(int i=0;i<m;i++) {
			b[i] = sc.nextInt();
			if(min2>b[i]) min2 = b[i];
			freb[b[i]]++;
		}
		int ans = 0;
		for(int i=0;i<10;i++) {
			if(frea[i]!=0 && freb[i]!=0) {
				ans = i;
				break;
			}
		}
		if(ans!=0) System.out.println(ans);
		else System.out.println(Math.min(min1,min2)+""+Math.max(min1,min2));
    //	solution end \(^-^)/
    //		        |
    //		       / \
}}