#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void inout() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  inout();
  long long a, b;
  cin >> a >> b;
  long long mi = INT_MAX, mi1 = mi, v, x[a], y[b], hx[10] = {0}, hy[10] = {0},
            ans = 10;
  for (long long i = 0; i < a; i++) {
    cin >> x[i];
    mi = min(mi, x[i]);
    hx[x[i]]++;
  }
  for (long long j = 0; j < b; j++) {
    cin >> y[j];
    mi1 = min(mi1, y[j]);
    if (hx[y[j]]) {
      ans = min(ans, y[j]);
    }
    hy[y[j]]++;
  }
  if (ans < 10) {
    cout << ans << ("\n");
    return 0;
  }
  cout << min(mi, mi1) << max(mi, mi1) << ("\n");
}
