#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t size1, size2, min1, min2, min3 = 10;
  cin >> size1 >> size2;
  int *list1 = new int[size1];
  int *list2 = new int[size2];
  for (size_t i = 0; i < size1; i++) cin >> list1[i];
  for (size_t i = 0; i < size2; i++) cin >> list2[i];
  min1 = 10;
  min2 = 10;
  for (size_t i = 0; i < size1; i++) {
    if (list1[i] < min1 && list1[i] > 0) min1 = list1[i];
  }
  for (size_t i = 0; i < size2; i++) {
    if (list2[i] < min2 && list2[i] > 0) min2 = list2[i];
  }
  for (size_t i = 0; i < size1; i++) {
    for (size_t j = 0; j < size2; j++) {
      if (list2[j] == list1[i] && list2[j] < min3 && list2[j] > 0)
        min3 = list2[j];
    }
  }
  if (min3 != 10)
    cout << min3;
  else {
    if (min1 > min2) cout << min2 << min1;
    if (min2 > min1) cout << min1 << min2;
    if (min2 == min1) cout << min1;
  }
}
