#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
int primes[100000];
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> arr1(n), arr2(m);
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> arr2[i];
  }
  sort(arr1.begin(), arr1.end());
  sort(arr2.begin(), arr2.end());
  if (arr1[0] == arr2[0]) {
    cout << arr1[0] << endl;
  } else {
    cout << arr1[0] << arr2[0] << endl;
  }
  return 0;
}
