#include <bits/stdc++.h>
using namespace std;
int smallestprettynumber(vector<int> dls, vector<int> jls, int n, int m) {
  sort(dls.begin(), dls.end());
  sort(jls.begin(), jls.end());
  for (int i = 0; i < dls.size(); i++) {
    if (binary_search(jls.begin(), jls.end(), dls[i])) return dls[i];
  }
  int min1 = *min_element(dls.begin(), dls.end());
  int min2 = *min_element(jls.begin(), jls.end());
  if (min1 < min2) return min1 * 10 + min2;
  return min2 * 10 + min1;
}
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> jls(m);
  vector<int> dls(n);
  for (int i = 0; i < n; i++) {
    cin >> dls[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> jls[i];
  }
  cout << smallestprettynumber(dls, jls, n, m);
}
