#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int arr1[n];
  int arr2[m];
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int i = 0; i < m; i++) cin >> arr2[i];
  int m1 = *min_element(arr1, arr1 + n);
  int m2 = *min_element(arr2, arr2 + m);
  int c1 = 0, c2 = 0;
  for (auto x : arr1) {
    if (x == m2) c2 = 1;
  }
  for (auto x : arr2) {
    if (x == m1) c1 = 1;
  }
  if (c1)
    cout << m1 << "\n";
  else if (c2)
    cout << m2 << "\n";
  else {
    int a = min(m1, m2);
    int b = max(m1, m2);
    cout << a << b << "\n";
  }
  return 0;
}
