#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int arr[n], ar[m];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int j = 0; j < m; j++) {
    scanf("%d", &ar[j]);
  }
  int min = arr[0];
  int min1 = ar[0];
  for (int i = 0; i < n; i++) {
    if (min > arr[i] || min == 0) {
      min = arr[i];
    }
  }
  for (int j = 0; j < m; j++) {
    if (min1 > ar[j] || min1 == 0) {
      min1 = ar[j];
    }
  }
  if (min == min1) {
    printf("%d\n", min);
  } else {
    printf("%d%d\n", min, min1);
  }
  return 0;
}
