#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }
const int N = 2e5 + 10;
int a[N], b[N], f[N], n, m, k, t;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &t), ++a[t];
  for (int i = 1; i <= m; ++i) scanf("%d", &t), ++b[t];
  for (int i = 1; i <= 99; ++i) {
    int c = i % 10, d = i / 10;
    if ((a[c] || a[d]) && (b[c] || b[d])) return __builtin_printf("%d\n", i), 0;
  }
}
