#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, tmp;
  vector<int> vec1, vec2;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    vec1.push_back(tmp);
  }
  for (int i = 0; i < m; ++i) {
    cin >> tmp;
    vec2.push_back(tmp);
  }
  sort(vec1.begin(), vec1.end());
  sort(vec2.begin(), vec2.end());
  int small = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (vec1[i] == vec2[j]) {
        small = vec1[i];
        break;
      }
    }
    if (small != 0) break;
  }
  if (small == 0) {
    int min1, min2;
    min1 = vec1[0];
    min2 = vec2[0];
    if (min1 < min2)
      small = min1 * 10 + min2;
    else
      small = min2 * 10 + min1;
  }
  cout << small << endl;
  return 0;
}
