#include <bits/stdc++.h>
int main() {
  int n, m, a[20], b[20];
  while (~scanf("%d%d", &n, &m)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    while (n--) {
      int x;
      scanf("%d", &x);
      a[x] = 1;
    }
    while (m--) {
      int x;
      scanf("%d", &x);
      b[x] = 1;
    }
    int t = 0, aa, bb, f1 = 0, f2 = 0;
    for (int i = 1; i < 10; i++) {
      if (a[i] && b[i]) {
        t = i;
        break;
      }
      if (a[i] && !f1) aa = i, f1 = 1;
      if (b[i] && !f2) bb = i, f2 = 1;
    }
    if (t)
      printf("%d\n", t);
    else {
      if (aa < bb)
        printf("%d%d\n", aa, bb);
      else
        printf("%d%d\n", bb, aa);
    }
  }
  return 0;
}
