#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
bool aHas[10];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[n];
  int b[m];
  int mna = INF;
  int mnb = INF;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    mna = min(mna, a[i]);
    aHas[a[i]] = true;
  }
  int mnCommon = INF;
  for (int i = 0; i < m; ++i) {
    scanf("%d", b + i);
    mnb = min(mnb, b[i]);
    if (aHas[b[i]]) {
      mnCommon = min(mnCommon, b[i]);
    }
  }
  if (mnCommon != INF) {
    printf("%d\n", mnCommon);
  } else {
    printf("%d%d\n", min(mna, mnb), max(mna, mnb));
  }
  return 0;
}
