#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, a = 10, b = 10, aux;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> aux;
    a = min(a, aux);
  }
  for (i = 0; i < m; i++) {
    cin >> aux;
    b = min(b, aux);
  }
  if (a == b) {
    cout << a << endl;
  } else {
    cout << min(a, b) << max(a, b) << endl;
  }
}
