#include <bits/stdc++.h>
using namespace std;
int main() {
  int n1, n2, k, a;
  cin >> n1 >> n2;
  vector<int> arr1, arr2;
  for (int l = 0; l < n1; l++) {
    cin >> a;
    arr1.push_back(a);
  }
  for (int l = 0; l < n2; l++) {
    cin >> a;
    arr2.push_back(a);
  }
  sort(arr1.begin(), arr1.end());
  sort(arr2.begin(), arr2.end());
  for (int k = 0; k < arr1.size(); k++) {
    for (int l = 0; l < arr2.size(); l++) {
      if (arr1[k] == arr2[l]) {
        cout << arr1[k] << "\n";
        return 0;
      }
    }
  }
  if (arr1[0] < arr2[0]) {
    k = 10 * arr1[0] + arr2[0];
    cout << k << "\n";
  } else {
    k = 10 * arr2[0] + arr1[0];
    cout << k << "\n";
  }
  return 0;
}
