#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;
  int fr = 10, sc = 10;
  for (int i = 0; i < n; i++) {
    int rub;
    cin >> rub;
    fr = min(fr, rub);
  }
  for (int i = 0; i < m; i++) {
    int rub;
    cin >> rub;
    sc = min(sc, rub);
  }
  if (fr == sc) {
    cout << fr;
  } else {
    cout << min(fr, sc) << max(fr, sc);
  }
  cout << "\n";
  bye();
}
