#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  set<int> s1, s2;
  int d;
  for (int i = 0; i < n; ++i) {
    cin >> d;
    s1.insert(d);
  }
  for (int i = 0; i < m; ++i) {
    cin >> d;
    s2.insert(d);
  }
  for (int i = 1; i <= 9; ++i) {
    if (s1.find(i) != s1.end() && s2.find(i) != s2.end()) {
      cout << i;
      return 0;
    }
  }
  cout << min(*s1.begin(), *s2.begin()) << max(*s1.begin(), *s2.begin());
  return 0;
}
