#include <bits/stdc++.h>
using namespace std;
int a[100], b[100], n, m, mina = 100000, minb = 100000, k, mino = 100000, w = 0;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mina = min(mina, a[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    minb = min(minb, b[i]);
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        mino = min(mino, a[j]);
        w = -1;
      }
    }
  }
  if (w == -1) {
    cout << mino;
    return 0;
  } else {
    cout << min(mina * 10 + minb, minb * 10 + mina);
  }
}
