#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> numa(n), numb(m);
  for (int i = 0; i < n; i++) cin >> numa[i];
  for (int i = 0; i < m; i++) cin >> numb[i];
  for (int i = 1; i < 10; i++) {
    if (find(numa.begin(), numa.end(), numa.size()) != numa.end() &&
        find(numb.begin(), numb.end(), numb.size()) != numb.end()) {
      cout << i << endl;
      return 0;
    }
  }
  auto a = min_element(numa.begin(), numa.end());
  auto b = min_element(numb.begin(), numb.end());
  if (*a < *b) {
    cout << (*a * 10 + *b) << endl;
  } else {
    cout << (*b * 10 + *a) << endl;
  }
}
