#include <bits/stdc++.h>
int main(void) {
  int n, m;
  std::cin >> n;
  std::cin >> m;
  std::vector<int> first(n);
  std::vector<int> second(m);
  int tmp;
  for (int i = 0; i < n; i++) {
    std::cin >> tmp;
    first[i] = tmp;
  };
  for (int i = 0; i < m; i++) {
    std::cin >> tmp;
    second[i] = tmp;
  };
  int numb[2];
  numb[0] = *std::min_element(first.begin(), first.end());
  numb[1] = *std::min_element(second.begin(), second.end());
  if (numb[0] == numb[1]) {
    std::cout << numb[0];
  } else {
    int res = 10 * std::min(numb[0], numb[1]) + std::max(numb[0], numb[1]);
    std::cout << res;
  };
  return 0;
};
