#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  int mini = 100;
  int pol = 100;
  cin >> a >> b;
  while (a != 0) {
    int x;
    cin >> x;
    mini = min(mini, x);
    a--;
  }
  while (b != 0) {
    int q;
    cin >> q;
    pol = min(pol, q);
    b--;
  }
  if (mini != pol)
    cout << min(mini, pol) << max(mini, pol);
  else
    cout << mini;
}
