#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
int main() {
  int n, m, a[11], b[11], c[11];
  scanf("%d%d", &n, &m);
  bool flag = true;
  memset(c, 0, sizeof(c));
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), c[a[i]]++;
  sort(a, a + n);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]), c[b[i]]++;
  sort(b, b + m);
  for (int i = 1; i <= 9; i++)
    if (c[i] == 2) {
      printf("%d\n", i);
      flag = false;
      break;
    }
  if (flag)
    printf("%d\n",
           (a[0] <= b[0] ? a[0] : b[0]) * 10 + (a[0] >= b[0] ? a[0] : b[0]));
  return 0;
}
