import javax.swing.plaf.IconUIResource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {

    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner s = new FastScanner();
//        int t=sc.nextInt();
//        outer:while (t-->=1) {
        StringBuilder sb=new StringBuilder();
        int n=s.nextInt(),m=s.nextInt(),i,x,y;
        List<Integer> l1= new LinkedList<>();
        List<Integer> l2= new LinkedList<>();
        List<Integer> l3= new LinkedList<>();
        for(i=0;i<n;i++)
            l1.add(s.nextInt());
        for(i=0;i<m;i++)
            l2.add(s.nextInt());
        for(i=0;i<m;i++)
        {
            if(l1.contains(l2.get(i)))
                l3.add(l2.get(i));
        }
        if(l3.isEmpty())
        {
            x=Collections.min(l1);
            y=Collections.min(l2);
            sb.append(Math.min(x,y));
            sb.append(Math.max(x,y));
        }
        else
            sb.append(Collections.min(l3));
        System.out.print(sb);
    }



    static void sort(int[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a) l.add(i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }
    static void sortLong(long[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (long i : a) l.add((int)i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static void sortReverse(long[] a) {
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a) l.add(i);
        Collections.sort(l, Collections.reverseOrder());
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }


        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
        long[] readArrayLong(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}



