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