#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int minN, minM;
  cin >> minN;
  for (int i = 0; i < n - 1; i++) {
    int temp;
    cin >> temp;
    minN = min(minN, temp);
  }
  cin >> minM;
  for (int i = 0; i < m - 1; i++) {
    int temp;
    cin >> temp;
    minM = min(minM, temp);
  }
  if (minN > minM) {
    cout << minM << minN;
  } else if (minN < minM) {
    cout << minN << minM;
  } else {
    cout << minM;
  }
  cout << endl;
  return 0;
}
