#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[111], b[111], s[111];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s[a[i]]++;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    s[b[i]]++;
  }
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 1; i <= 9; i++)
    if (s[i] == 2) {
      printf("%d\n", i);
      return 0;
    }
  printf("%d%d\n", a[0], b[0]);
  return 0;
}
