#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, N, M, n1[10], n2[10];
  while (scanf("%d %d", &N, &M) == 2) {
    for (i = 0; i < N; i++) scanf("%d", &n1[i]);
    for (i = 0; i < M; i++) scanf("%d", &n2[i]);
    sort(n1, n1 + N);
    sort(n2, n2 + M);
    if (n1[0] == n2[0])
      printf("%d\n", n1[0]);
    else if (n1[0] < n2[0])
      printf("%d%d\n", n1[0], n2[0]);
    else
      printf("%d%d\n", n2[0], n1[0]);
  }
  return 0;
}
