#include <bits/stdc++.h>
int main() {
  int a[10] = {0};
  int b[10] = {0};
  int n, m, k, x = 9, y = 9;
  scanf("%d %d", &n, &m);
  for (k = 0; k < n; k++) scanf("%d", &a[k]);
  for (k = 0; k < m; k++) scanf("%d", &b[k]);
  for (k = 0; k < n; k++)
    if (x >= a[k]) x = a[k];
  for (k = 0; k < m; k++)
    if (y >= b[k]) y = b[k];
  if (x == y) printf("%d", x);
  if (x < y) printf("%d%d", x, y);
  if (x > y) printf("%d%d", y, x);
  return 0;
}
