#include <bits/stdc++.h>
int main() {
  int n, m, a, b, min = 10e5;
  scanf("%d %d", &n, &m);
  while (n--) {
    scanf("%d", &a);
    if (a < min) min = a;
  }
  a = min;
  min = 10e5;
  while (m--) {
    scanf("%d", &b);
    if (b < min) min = b;
  }
  b = min;
  if (a == b)
    printf("%d\n", a);
  else
    printf("%d\n", (a * 10 + b) < (b * 10 + a) ? (a * 10 + b) : (b * 10 + a));
  return 0;
}
