#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++) {
      if (a[i] != b[j]) {
        sum = (a[i] * 10) + b[j];
        c[k] = sum;
        k++;
      }
      if (a[i] == b[j]) {
        c[k] = a[i];
        k++;
      }
    }
  }
  sum = 0;
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (b[i] != a[j]) {
        sum = (b[i] * 10) + a[j];
        c[k] = sum;
        k++;
      }
      if (b[i] == a[j]) {
        c[k] = b[i];
        k++;
      }
    }
  }
  sort(c, c + p);
  printf("%d", c[0]);
  return 0;
}
