#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, n, m, i, j, k, l, r;
  cin >> n >> m;
  vector<int> vec(n);
  vector<int> vec1(m);
  vector<bool> prov(10);
  vector<bool> prov1(10);
  for (i = 0; i < n; ++i) {
    cin >> vec[i];
    prov[vec[i] - 1] = 1;
  }
  for (i = 0; i < m; ++i) {
    cin >> vec1[i];
    prov1[vec1[i] - 1] = 1;
  }
  r = 0;
  for (i = 0; r == 0 && i < 9; ++i) {
    if (prov[i] == 1 && prov[i] == prov1[i]) {
      r = 1;
      cout << i + 1;
    }
  }
  sort(vec.begin(), vec.end());
  sort(vec1.begin(), vec1.end());
  if (r == 0) {
    if (vec[0] > vec1[0])
      cout << vec1[0] << vec[0];
    else
      cout << vec[0] << vec1[0];
  }
  return 0;
}
