#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int INF = 1e9 + 7;
const long double EPS = 1e-9;
const long double PI = 3.141592653589793;
inline void start(void) {
  cout << fixed << setprecision(16);
  srand(INF);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
inline void bye(void) { exit(0); }
int main(void) {
  start();
  int n, m;
  cin >> n >> m;
  vector<int> frr(n), scc(m);
  int fr = 10, sc = 10;
  int bu = 10;
  for (int i = 0; i < n; i++) {
    cin >> frr[i];
    fr = min(fr, frr[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> scc[i];
    sc = min(sc, scc[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (frr[i] == scc[j]) {
        bu = min(bu, frr[i]);
      }
    }
  }
  if (fr >= sc) {
    swap(fr, sc);
  }
  cerr << fr << " " << sc << "\n";
  cerr << (find(frr.begin(), frr.end(), fr) != frr.end())
       << (find(scc.begin(), scc.end(), fr) != scc.end()) << "\n";
  cerr << (find(frr.begin(), frr.end(), sc) != frr.end())
       << (find(scc.begin(), scc.end(), sc) != scc.end()) << "\n";
  if (bu != 10) {
    cout << bu;
  } else if (find(frr.begin(), frr.end(), fr) != frr.end() &&
             find(scc.begin(), scc.end(), fr) != scc.end()) {
    cout << fr;
  } else if (find(frr.begin(), frr.end(), sc) != frr.end() &&
             find(scc.begin(), scc.end(), sc) != scc.end()) {
    cout << sc;
  } else {
    cout << fr << sc;
  }
  cout << "\n";
  bye();
}
