#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e6 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double EPS = 1e-9;
int a[MXN], b[MXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, mn = MOD, mg = MOD, ans = MOD;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mn = min(mn, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    mg = min(mg, b[i]);
    for (int j = 1; j <= n; j++) {
      if (b[i] == a[j]) {
        ans = min(ans, a[j]);
      }
    }
  }
  if (ans != MOD)
    cout << ans;
  else if (mn == mg)
    cout << mn;
  else
    cout << min(mn, mg) << max(mn, mg);
  return 0;
}
