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