#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 1e9 + 7;
double eps = 1e-6;
int vn[15], vm[15];
int ap[15];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> vn[i];
  for (long long i = 1; i <= m; i++) cin >> vm[i];
  int minn = 10, minm = 10;
  for (long long i = 1; i <= n; i++) {
    minn = min(minn, vn[i]);
    ap[vn[i]]++;
  }
  for (long long i = 1; i <= m; i++) {
    minm = min(minm, vm[i]);
    ap[vm[i]]++;
  }
  for (long long i = 1; i <= 10; i++) {
    if (ap[i] == 2) {
      cout << i;
      return 0;
    }
  }
  cout << min(minn, minm) << max(minm, minn);
  return 0;
}
