#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 1;
string getString(int n) {
  char anf[n];
  scanf(" %s ", anf);
  return string(anf);
}
int a[10], b[10];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int mn1 = 10, mn2 = 10;
  for (int i = 0; i < n; ++i) {
    int t;
    scanf("%d", &t);
    a[t] = 1;
    mn1 = min(mn1, t);
  }
  for (int i = 0; i < m; ++i) {
    int t;
    scanf("%d", &t);
    b[t] = 1;
    mn2 = min(mn2, t);
  }
  for (int i = 1; i < 10; ++i) {
    if (a[i] && b[i]) {
      printf("%d", i);
      return 0;
    }
  }
  printf("%d%d", mn1, mn2);
}
