#include <bits/stdc++.h>
int main() {
  int m, n, ma = 11, mb = 11;
  int ans = 110;
  scanf("%d%d", &m, &n);
  int fl[11], sl[11];
  for (int a = 0; a < m; a++) {
    scanf("%d", &fl[a]);
    if (fl[a] < ma) ma = fl[a];
  }
  for (int a = 0; a < n; a++) {
    scanf("%d", &sl[a]);
    if (sl[a] < mb) mb = sl[a];
  }
  for (int a = 0; a < m; a++)
    for (int b = 0; b < n; b++) {
      if (fl[a] == sl[b] && fl[a] < ans) ans = fl[a];
    }
  if (ma * 10 + mb < ans) ans = ma * 10 + mb;
  if (mb * 10 + ma < ans) ans = mb * 10 + ma;
  printf("%d", ans);
  return 0;
}
