#include <bits/stdc++.h>
using namespace std;
int aa[12];
int bb[12];
int main() {
  int a, b;
  cin >> a >> b;
  int v, amin, bmin;
  amin = bmin = 10;
  for (int i = 0; i < a; i++) {
    cin >> v;
    aa[i] = v;
    if (v < amin) amin = v;
  }
  for (int i = 0; i < b; i++) {
    cin >> v;
    bb[i] = v;
    if (v < bmin) bmin = v;
  }
  sort(aa, aa + a);
  sort(bb, bb + b);
  for (int i = 0, j = 0; i < a, j < b; i, j) {
    if (aa[i] == bb[j]) {
      cout << aa[i] << endl;
      return 0;
    } else {
      if (aa[i] > bb[j]) {
        j++;
      } else {
        i++;
      }
    }
    if (i == a || j == b) {
      i = a + 1;
      j = b + 1;
    }
  }
  if (amin > bmin) swap(amin, bmin);
  cout << amin << bmin << endl;
}
