#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[9], b[9], mina = 10, minb = 10;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < mina) mina = a[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    if (b[i] < minb) minb = b[i];
  }
  if (mina == minb)
    printf("%d", mina);
  else
    printf("%d", min(mina, minb) * 10 + max(mina, minb));
  return 0;
}
