#include <bits/stdc++.h>
using namespace std;
set<int> s;
set<int> s2;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int num;
    cin >> num;
    s.insert(num);
  }
  for (int i = 1; i <= m; i++) {
    int num;
    cin >> num;
    s2.insert(num);
  }
  if (*s.begin() == *s2.begin()) {
    cout << *s.begin() << endl;
  } else {
    if (*s.begin() < *s2.begin()) {
      cout << *s.begin() << *s2.begin() << endl;
    } else {
      cout << *s2.begin() << *s.begin() << endl;
    }
  }
  return 0;
}
