#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  long long n, i, a, min1, c, d, m, b;
  cin >> n >> m;
  vector<long long> v1, v2, v3;
  while (n--) {
    cin >> a;
    v1.push_back(a);
  }
  while (m--) {
    cin >> a;
    v2.push_back(a);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(),
                   back_inserter(v3));
  a = v1[0];
  b = v2[0];
  c = a * 10 + b;
  d = b * 10 + a;
  min1 = min(c, d);
  if (v3.size() > 0) {
    sort(v3.begin(), v3.end());
    min1 = min(min1, v3.front());
  }
  cout << min1;
  return 0;
}
