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