#include <bits/stdc++.h>
int main() {
  int n1, n2;
  std::cin >> n1 >> n2;
  std::vector<int> v1(n1), v2(n2);
  std::set<int> se1;
  for (int i = 0; i < n1; i++) {
    std::cin >> v1[i];
    se1.insert(v1[i]);
  }
  for (int i = 0; i < n2; i++) std::cin >> v2[i];
  std::sort(v1.begin(), v1.end());
  std::sort(v2.begin(), v2.end());
  for (int i = 0; i < n2; i++)
    if (!se1.insert(v2[i]).second) {
      std::cout << v2[i];
      return 0;
    }
  if (v1[0] <= v2[0])
    std::cout << v1[0] << v2[0];
  else
    std::cout << v2[0] << v1[0];
}
