#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int A[9] = {0}, B[9] = {0}, n, m, i, mi1, mi2, miravn;
  cin >> n >> m;
  mi1 = 10;
  mi2 = 10;
  miravn = 10;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] < mi1) mi1 = A[i];
  }
  for (i = 0; i < m; i++) {
    cin >> B[i];
    if (B[i] < mi2) mi2 = B[i];
    for (int j = 0; j < n; j++)
      if ((B[i] == A[j]) && (A[j] < miravn)) miravn = A[j];
  }
  if (mi1 == mi2)
    cout << mi1;
  else if (miravn < 10)
    cout << miravn;
  else
    cout << min(mi1, mi2) << max(mi1, mi2);
  return 0;
}
