#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
int a[maxn];
int b[maxn];
int main() {
  int n, m, x, y, rslt = 10;
  x = y = 10;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < x) x = a[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    if (b[i] < y) y = b[i];
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) rslt = b[i];
    }
  }
  if (rslt < maxn)
    printf("%d\n", rslt);
  else {
    if (x > y) swap(x, y);
    printf("%d%d\n", x, y);
  }
}
