#include <bits/stdc++.h>
using namespace std;
long long bgm(long long a, long long b, long long m) {
  a %= m;
  long long rem = 1;
  while (b) {
    if (b & 1) rem = (rem * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return rem;
}
long long in() {
  long long a;
  if (scanf("%lld", &a) == EOF) return EOF;
  return a;
}
long long dl() {
  double a;
  if (scanf("%lf", &a) == EOF) return EOF;
  return a;
}
const int MAX = 100005;
vector<int> a, b;
int cnt[10];
int main() {
  int n = in(), m = in();
  while (n--) a.push_back(in());
  while (m--) b.push_back(in());
  sort((a).begin(), (a).end()), sort((b).begin(), (b).end());
  for (int i = 0; i < a.size(); i++) cnt[a[i]] = 1;
  for (int i = 0; i < b.size(); i++) {
    if (cnt[b[i]]) {
      printf("%lld", (long long)(b[i])), puts("");
      exit(0);
    }
  }
  int x = *min_element((a).begin(), (a).end()),
      y = *min_element((b).begin(), (b).end());
  if (x > y) swap(x, y);
  if (x != y) x = x * 10 + y;
  printf("%lld", (long long)(x)), puts("");
  return 0;
}
