import java.util.*;

public class Solution {

  private static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int n = sc.nextInt(), m = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[m];
    for (int i = 0; i < n; i++) a[i] =sc.nextInt();
    for (int i = 0; i < m; i++) b[i] =sc.nextInt();
    int res = 100500;
    for (int i : a) {
      for (int j : b) {
        if (i == j) {
          res = Math.min(res, i);
        } else {
          res = Math.min(res, i * 10 + j);
          res = Math.min(res, j * 10 + i);
        }
      }
    }
    System.out.println(res);
  }
}