import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String values = sc.nextLine();
String[] length = values.split(" ");

String firstin = sc.nextLine();
String[] firsts = firstin.split(" ");
int[] first = new int[firsts.length];
for(int i = 0; i < firsts.length; i++) {
    first[i] = Integer.parseInt(firsts[i]);
}

String secondin = sc.nextLine();
String[] seconds = secondin.split(" ");
int[] second = new int[seconds.length];
for(int i = 0; i < seconds.length; i++) {
    second[i] = Integer.parseInt(seconds[i]);
}
int smallest = 10;
for (int i = 0; i < first.length; i++) {
    for(int j = 0; j < second.length; j++) {
        if(first[i] == second[j]) {
            if(first[i] < smallest) {
                smallest = first[i];
            }
    }
}
}
if(smallest == 10) {
    int smst1 = 10;
    int smst2 = 10;
    for(int i = 0; i < first.length; i++) {
        if(first[i] < smst1) {
            smst1 = first[i];
        }
    }
    for(int i = 0; i < second.length; i++) {
        if(second[i] < smst2) {
            smst2 = second[i];
        }
    }
    if (smst1 < smst2) {
        System.out.println(Integer.toString(smst1) + Integer.toString(smst2));
    } else {
        System.out.println(Integer.toString(smst2) + Integer.toString(smst1));
    }
    
} else {
    System.out.println(smallest);
}

}
}