#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v1(n), v2(m);
  for (int &n1 : v1) cin >> n1;
  for (int &n1 : v2) cin >> n1;
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1[0] == v2[0]) {
    cout << v1[0];
    return 0;
  }
  v1[0] > v2[0] ? cout << v2[0] << v1[0] : cout << v1[0] << v2[0];
  return 0;
}
