#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s = 0, l = 0;
  cin >> n >> m;
  int a[n + 1], b[m + 1], mi1 = 10, mi = 10;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mi = min(mi, a[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    mi1 = min(mi1, b[i]);
  }
  if (mi == mi1) {
    cout << mi;
    return 0;
  } else {
    s = min(mi, mi1);
    l = max(mi, mi1);
    cout << s * 10 + l;
  }
  return 0;
}
