#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, m, a[9], b[9], amin = 10, bmin = 10;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < amin) amin = a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
    if (b[i] < bmin) bmin = b[i];
  }
  for (i = 0; i < m; i++)
    if (amin == b[i]) {
      cout << amin;
      return 0;
    }
  for (i = 0; i < n; i++)
    if (bmin == a[i]) {
      cout << bmin;
      return 0;
    }
  if (amin == bmin)
    cout << amin;
  else
    cout << min(amin, bmin) << max(amin, bmin);
  return 0;
}
