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