#include <bits/stdc++.h>
using namespace std;
int minF(int counter) {
  int out, temp;
  cin >> out;
  for (int i = 1; i < counter; i++) {
    cin >> temp;
    if (temp < out) out = temp;
  }
  return out;
}
int main() {
  int c1, c2, min1, min2;
  cin >> c1 >> c2;
  min1 = minF(c1);
  min2 = minF(c2);
  if (min1 < min2)
    cout << min1 << min2;
  else if (min2 < min1)
    cout << min2 << min1;
  return 0;
}
