import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
public class PrettyInteger{
    public static void main(String[] args) {
        MyScanner sc=new MyScanner();
        int n=sc.nextInt();
        int m=sc.nextInt();
        ArrayList<Integer> ans=new ArrayList<>();
        int an[]=new int[n];
        int am[]=new int[m];
        for(int i=0;i<n;i++) an[i]=sc.nextInt();
        for(int i=0;i<m;i++) am[i]=sc.nextInt();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(an[i]==am[j]) ans.add(an[i]);
                ans.add(an[i]*10+am[j]);
                ans.add(am[j]*10+an[i]);
            }
        }
        ans.sort(null);
        System.out.println(ans.get(0));
    }


    private static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

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

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

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

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}