#include <bits/stdc++.h>
using namespace std;
int n, m, minn = 0x3f3f3f, minnn = 0x3f3f3f, a, b, ans = 0x3f3f3f3f;
bool ex[10], fd = 0;
int main() {
  cin >> n >> m;
  while (n--) {
    cin >> a;
    minn = min(minn, a);
    ex[a] = true;
  }
  while (m--) {
    cin >> a;
    minnn = min(minnn, a);
    if (ex[a]) fd = true, ans = min(ans, a);
  }
  if (fd) {
    cout << ans;
  } else {
    cout << min(minn, minnn) << max(minn, minnn);
  }
}
