#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v1, v2;
  vector<int>::iterator it;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v1.push_back(x);
  }
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    v2.push_back(x);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1[0] == v2[0])
    cout << v1[0] << endl;
  else if (v1[0] > v2[0]) {
    cout << v2[0] << v1[0] << endl;
  } else {
    cout << v1[0] << v2[0] << endl;
  }
}
