#include <bits/stdc++.h>
using namespace std;
int a[100001], b[100001];
int main() {
  int n, m;
  cin >> n >> m;
  int mi1 = 100, mi2 = 100;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mi1) mi1 = a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    if (b[i] < mi2) mi2 = b[i];
  }
  if (mi1 == mi2)
    cout << mi1;
  else {
    if (mi1 < mi2)
      cout << mi1 << mi2;
    else
      cout << mi2 << mi1;
  }
}
