#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);
  }
  long long flag = 0;
  for (auto its1 = v1.begin(); its1 != v1.end(); its1++) {
    for (auto its2 = v2.begin(); its2 != v2.end(); its2++) {
      if (*its2 == *its1) {
        cout << *its2;
        flag = 1;
      }
    }
    if (flag == 1) {
      break;
    }
  }
  if (flag == 0) {
    auto it1 = v1.begin(), it2 = v2.begin();
    long long sum = 0;
    sum += min(*it1, *it2);
    sum *= 10;
    sum += max(*it1, *it2);
    cout << sum;
  }
  return 0;
}
