#include <bits/stdc++.h>
using namespace std;
int main() {
  int t[9], a[9];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  sort(t, t + n);
  sort(a, a + m);
  int i = 0, j, nb;
  bool ok = false;
  while (i < n && !ok) {
    j = 0;
    while (j < m && !ok) {
      if (t[i] == a[j]) {
        ok = true;
        nb = t[i];
      }
      j++;
    }
    i++;
  }
  if (ok) {
    cout << nb;
  } else {
    cout << min(t[0], a[0]) * 10 + max(a[0], t[0]);
  }
  return 0;
}
