#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k = 0, p, sum = 0, temp = 0, first = 0, last = 0, s = 0;
  cin >> n >> m;
  p = 2 * n * m;
  int a[n], b[m], c[2 * n * m];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (j = 0; j < m; j++) {
    cin >> b[j];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      sum = (a[i] * 10) + b[j];
      c[k] = sum;
      k++;
    }
  }
  sum = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      sum = (b[i] * 10) + a[j];
      c[k] = sum;
      k++;
    }
  }
  sort(c, c + p);
  temp = c[0];
  while (temp != 0) {
    if (n == 1) {
      printf("%d", a[n - 1]);
      break;
    }
    if (m == 1) {
      printf("%d", b[m - 1]);
      break;
    }
    s = temp % 10;
    temp = temp / 10;
    if (temp != 0) {
      first = s;
    }
    if (temp == 0) {
      last = s;
      if (first == last) {
        printf("%d", first);
      } else {
        printf("%d", c[0]);
      }
      break;
    }
  }
  return 0;
}
