#include <bits/stdc++.h>
using namespace std;
int n, m, minn = 0x3f3f3f, minnn = 0x3f3f3f, a, b;
int main() {
  cin >> n >> m;
  while (n--) {
    cin >> a;
    minn = min(minn, a);
  }
  while (m--) {
    cin >> a;
    minnn = min(minnn, a);
  }
  if (minn == minnn) {
    cout << minn;
  } else {
    cout << min(minn, minnn) << max(minn, minnn);
  }
}
