import java.util.*;
import java.io.*;
public class A{
       public static void main(String args[])throws IOException{
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              StringTokenizer st = new StringTokenizer(br.readLine());
              int n = Integer.parseInt(st.nextToken());
              int m = Integer.parseInt(st.nextToken());
              int a[] = new int[10];
              int b[] = new int[10];
              st = new StringTokenizer(br.readLine());
              for(int i = 0; i < n; i++)
                     a[Integer.parseInt(st.nextToken())]++;
              st = new StringTokenizer(br.readLine());
              for(int j = 0; j < m; j++)
                     b[Integer.parseInt(st.nextToken())]++;
              int ans = 0;
              for(int i = 1; i < 10; i++){
                     if(a[i] > 0 && b[i] > 0){
                            ans = i;
                            break;
                     }
              }
              if(ans > 0){
                     System.out.println(ans);
              }else{
                     int first = 0;
                     int second = 0;
                     for(int i = 0; i < 10; i++){
                            if(a[i] > 0){
                                   first = i;
                                   break;
                            }
                     }
                     for(int i = 0; i < 10; i++){
                            if(b[i] > 0){
                                   second = i;
                                   break;
                            }
                     }
                     ans += Math.min(first, second);
                     ans *= 10;
                     ans += Math.max(first, second);
                     System.out.println(ans);
              }
       }
}