#include <bits/stdc++.h>
int main() {
  int n, m;
  int a[20], b[20];
  while (~scanf("%d%d", &n, &m)) {
    int nn = 1e9, x;
    while (n--) {
      scanf("%d", &x);
      if (x < nn) nn = x;
    }
    int mm = 1e9;
    while (m--) {
      scanf("%d", &x);
      if (x < mm) mm = x;
    }
    if (mm == nn)
      printf("%d\n", mm);
    else {
      if (nn > mm)
        printf("%d%d\n", mm, nn);
      else
        printf("%d%d\n", nn, mm);
    }
  }
  return 0;
}
