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