import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean flag = true;
        int N = in.nextInt();
        int M = in.nextInt();
        int[] a = new int[N];
        int[] b = new int[M];
        for (int i = 0; i < N; i++) {
            a[i]=in.nextInt();
        }
        for (int i = 0; i < M; i++) {
            b[i]=in.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        for(int i=0;i<N && flag;i++){
            for(int j=0;j<M;j++){
                if(a[i]==b[j]){
                    System.out.print(a[i]);
                    flag=false;
                    break;
                }
            }
        }
        if(flag) {
            if (a[0] > b[0]) {
                System.out.print(a[0] + 10 * b[0]);
            } else {
                System.out.print(b[0] + 10 * a[0]);
            }
        }
    }
}
