import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static boolean search (Integer[] arr, int key, int min, int max) {
    for (int i = 0; i < arr.length; i++) {
      if (arr[i] == key) {
        return true;
      }
    }
    return false;
  }

  public static int findMin (Integer[] arr) {
    int min = arr[0];
    for (int i = 1; i < arr.length; i++) {
      if (arr[i] < min) {
        min = arr[i];
      }
    }
    return min;
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int lenOne = in.nextInt();
    int lenTwo = in.nextInt();
    Integer[] arrOne = new Integer[lenOne];
    Integer[] arrTwo = new Integer[lenTwo];
    ArrayList<Integer> common = new ArrayList();

    for (int i = 0; i < lenOne; i++) {
      arrOne[i] = in.nextInt();
    }
    for (int i = 0; i < lenTwo; i++) {
      arrTwo[i] = in.nextInt();
    }
    for (int i = 0; i < lenOne; i++) {
      if (search(arrTwo, arrOne[i], 0, arrTwo.length)) {
        common.add(arrOne[i]);
      }
    }
    if (!common.isEmpty()) {
      Integer[] x = common.toArray(new Integer[common.size()]);
      int retVal = findMin(x);
      System.out.println(retVal);
    } else {
      int digitOne = findMin(arrOne);
      int digitTwo = findMin(arrTwo);
      if (digitOne <= digitTwo) {
        System.out.println(digitOne*10 + digitTwo);
      } else {
        System.out.println(digitTwo*10 + digitOne);
      }
    }
  }
}
