#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, menor = 999999999, menor2 = 999999999, c;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> c;
    if (menor > c) {
      menor = c;
    }
  }
  for (int i = 0; i < b; i++) {
    cin >> c;
    if (menor2 > c) {
      menor2 = c;
    }
  }
  if (menor == menor2) {
    cout << menor;
  } else {
    cout << min(menor, menor2) << max(menor, menor2);
  }
}
