#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[21], b[20];
  int x[15], y[15];
  memset(x, 0, sizeof(x));
  memset(y, 0, sizeof(y));
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    x[a[i]]++;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    y[b[i]]++;
  }
  sort(a, a + n);
  sort(b, b + m);
  int t = 0;
  for (int i = 1; i <= 9; i++) {
    if (x[i] > 0 && y[i] > 0) {
      printf("%d\n", i);
      t = 1;
      break;
    }
  }
  if (t == 0) {
    int q, w;
    q = a[0] * 10 + b[0];
    w = a[0] + b[0] * 10;
    if (q > w)
      printf("%d\n", w);
    else
      printf("%d\n", q);
  }
  return 0;
}
