#include <bits/stdc++.h>
int main() {
  int list1[9], list2[9], minList1 = 10, minList2 = 10;
  int lenList1, lenList2;
  scanf("%d %d", &lenList1, &lenList2);
  for (int i = 0; i < lenList1; i++) {
    scanf("%d", &list1[i]);
    if (list1[i] < minList1) {
      minList1 = list1[i];
    }
  }
  for (int i = 0; i < lenList2; i++) {
    scanf("%d", &list2[i]);
    if (list2[i] < minList2) {
      minList2 = list2[i];
    }
  }
  int valid = 0;
  int hasil = list1[0], x = 0;
  for (int i = 0; i < lenList1; i++) {
    for (int j = 0; j < lenList2; j++) {
      if (list1[i] == list2[j]) {
        if (list1[i] < hasil) {
          hasil = list1[i];
          valid = 0;
        }
      }
    }
  }
  if (!valid) {
    printf("%d", hasil);
    return 0;
  }
  if (minList1 < minList2) {
    printf("%d%d", minList1, minList2);
  } else if (minList2 < minList1) {
    printf("%d%d", minList2, minList1);
  }
  return 0;
}
