#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  int m1, m2, t1, t2;
  cin >> m1;
  for (int i = 1; i < x; i++) {
    cin >> t1;
    if (m1 > t1) m1 = t1;
  }
  cin >> m2;
  for (int i = 1; i < y; i++) {
    cin >> t2;
    if (m2 > t2) m2 = t2;
  }
  if (m1 == m2)
    cout << m1;
  else if (m1 < m2)
    cout << m1 << m2;
  else
    cout << m2 << m1;
  return 0;
}
