#include <bits/stdc++.h>
using namespace std;
int n, m, i, mn = INT_MAX, j;
int s = INT_MAX, ss = INT_MAX;
int a[9], b[9];
signed main() {
  cin >> n >> m;
  for (i = 0; i < n && cin >> a[i]; i++) {
    s = min(s, a[i]);
  }
  for (i = 0; i < m && cin >> b[i]; i++) {
    bool ok = 0;
    for (j = 0; j < n; j++) {
      ok |= (a[j] == b[i]);
    }
    if (ok) mn = min(mn, b[i]);
    ss = min(ss, b[i]);
  }
  if (mn != INT_MAX) {
    cout << mn << '\n';
  } else {
    cout << min(s, ss) * 10 + max(s, ss) << '\n';
  }
  return 0;
}
