#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int sn = 10, sm = 10;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    sn = min(sn, num);
  }
  for (int i = 0; i < m; i++) {
    int num;
    cin >> num;
    sm = min(sm, num);
  }
  if (sm == sn)
    cout << sm << endl;
  else if (sn < sm)
    cout << sn << sm << endl;
  else
    cout << sm << sn << endl;
}
