
import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] masN = new int[n];
        int[] masM = new int[m];
        int min1 = 10;
        int min2 = 10;
        for(int i = 0; i < n; i++){
            masN[i] = sc.nextInt();
            if(min1 > masN[i]){
                min1 = masN[i];
            }
        }
        for(int i = 0; i < m; i++){
            masM[i] = sc.nextInt();
            if(min2 > masM[i]){
                min2 = masM[i];
            }
        }
        int min = 10;
        for(int i = 0; i < n;i++){
            for(int j = 0; j < m ;j++){
                if(masN[i] == masM[j] && min > masN[i]){
                    min = masN[i];
                }
            }
        }
        if(min == 10) {
            if (min1 > min2) {
                min = min1;
                min1 = min2;
                min2 = min;
            }
            System.out.print(min1 + "" + min2);
        }else
            System.out.print(min);

    }

    static class TimeLine implements Comparable<TimeLine>{
        int a;
        int type;

        public TimeLine(int a, int type){
            this.a = a;
            this.type = type;
        }
        @Override
        public int compareTo(TimeLine o) {
            if(a != o.a)return a - o.a;
            return type - o.type;
        }
    }
}
