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