#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l1, l2, t;
  set<long long> v1, v2;
  cin >> l1 >> l2;
  for (long long i = 0; i < l1; i++) {
    cin >> t;
    v1.insert(t);
  }
  for (long long i = 0; i < l2; i++) {
    cin >> t;
    v2.insert(t);
  }
  auto it1 = v1.begin(), it2 = v2.begin();
  long long sum = 0;
  sum += min(*it1, *it2);
  sum *= 10;
  sum += max(*it1, *it2);
  if (*it1 == *it2) {
    sum = *it1;
  }
  cout << sum;
  return 0;
}
