#include <bits/stdc++.h>
const bool debugging = 1;
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N);
  vector<long long> B(M);
  set<long long> inA;
  set<long long> common;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    inA.insert(A[i]);
  }
  for (long long i = 0; i < M; i++) {
    cin >> B[i];
    if (inA.find(B[i]) != inA.end()) {
      common.insert(B[i]);
    }
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (common.size() != 0) {
    cout << *common.begin() << "\n";
  } else {
    long long x = min(A[0], B[0]);
    long long y = max(A[0], B[0]);
    cout << x * 10 + y << "\n";
  }
  return 0;
}
