#include <bits/stdc++.h>
int main() {
  int n, m, i, xi = 99999, max = 9999, x, y, sum = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x < max) {
      max = x;
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &y);
    if (y < xi) {
      xi = y;
    }
  }
  if (xi < max) {
    sum = (xi * 10) + max;
  } else if (xi == max)
    sum = xi;
  else
    sum = (max * 10) + xi;
  printf("%d", sum);
  return 0;
}
