#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  short n, m, p, smallN = 10, smallM = 10;
  cin >> n >> m;
  short arr1[n], arr2[m], common = 10;
  for (short i = 0; i < n; i++) {
    cin >> arr1[i];
    smallN = min(smallN, arr1[i]);
  }
  for (short i = 0; i < m; i++) {
    cin >> arr2[i];
    smallM = min(smallM, arr2[i]);
  }
  for (short i = 0; i < n; i++) {
    for (short j = 0; j < m; j++) {
      if (arr1[i] == arr2[j]) {
        common = min(common, arr1[i]);
      }
    }
  }
  common != 10      ? cout << common
  : smallN > smallM ? cout << smallM << smallN
                    : cout << smallN << smallM;
}
