#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::set<int> a;
  int x;
  for (int i = 0; i < n; ++i) {
    std::cin >> x;
    a.insert(x);
  }
  std::set<int> b;
  int min = 15;
  for (int i = 0; i < m; ++i) {
    std::cin >> x;
    if (a.count(x) && x < min) {
      min = x;
    }
    b.insert(x);
  }
  if (min != 15) {
    std::cout << min;
    return 0;
  }
  if (*(a.begin()) < *(b.begin())) {
    std::cout << *(a.begin()) << *(b.begin());
  } else {
    std::cout << *(b.begin()) << *(a.begin());
  }
  return 0;
}
