#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, a, b, c = 0;
  cin >> n >> k;
  int ar[n], aa[k];
  for (a = 0; a < n + k; a++) {
    if (a < n)
      cin >> ar[a];
    else
      cin >> aa[a - n];
  }
  sort(ar, ar + n);
  sort(aa, aa + k);
  for (a = 0; a < n; a++) {
    for (b = 0; b < k; b++) {
      if (ar[a] == aa[b]) {
        cout << ar[a];
        return 0;
      }
    }
  }
  if (aa[0] > ar[0])
    cout << 10 * ar[0] + aa[0];
  else
    cout << 10 * aa[0] + ar[0];
}
