#include <bits/stdc++.h>
int main(int argc, char** argv) {
  using namespace std;
  using list = vector<int>;
  int first_size = 0;
  int second_size = 0;
  cin >> first_size >> second_size;
  list first_list;
  list second_list;
  auto read_from_cin = [](list& l, int buffer_size) {
    for (auto i = 0; i < buffer_size; i++) {
      int temp = 0;
      cin >> temp;
      l.push_back(temp);
    }
  };
  read_from_cin(first_list, first_size);
  read_from_cin(second_list, second_size);
  int min_first = *min_element(first_list.begin(), first_list.end());
  int min_second = *min_element(second_list.begin(), second_list.end());
  int beatiful_number = 0;
  if (min_first == min_second) {
    beatiful_number = min_first;
  } else {
    beatiful_number =
        std::min(min_first, min_second) * 10 + std::max(min_first, min_second);
  }
  cout << beatiful_number << endl;
  return 0;
}
