#include <bits/stdc++.h>
using namespace std;
vector<int> vIntersection(vector<int> vFirst, vector<int> vLast) {
  vector<int> vInter;
  sort(vFirst.begin(), vFirst.end());
  sort(vLast.begin(), vLast.end());
  set_intersection(vFirst.begin(), vFirst.end(), vLast.begin(), vLast.end(),
                   back_inserter(vInter));
  return vInter;
}
int main() {
  int lenFirst = 0, lenSecond = 0;
  cin >> lenFirst >> lenSecond;
  vector<int> vFirst, vSecond;
  int temp = 0;
  for (int i = 0; i < lenFirst; i++) {
    cin >> temp;
    vFirst.push_back(temp);
  }
  for (int i = 0; i < lenSecond; i++) {
    cin >> temp;
    vSecond.push_back(temp);
  }
  vector<int> vInter = vIntersection(vFirst, vSecond);
  int answer = 0;
  if (vInter.size() == 0) {
    int vFirstMin = *min_element(vFirst.begin(), vFirst.end());
    int vSecondMin = *min_element(vSecond.begin(), vSecond.end());
    if (vFirstMin > vSecondMin) {
      swap(vFirstMin, vSecondMin);
    }
    cout << vFirstMin << vSecondMin;
  } else {
    cout << *min_element(vInter.begin(), vInter.end());
  }
  cout << endl;
  return 0;
}
