#include <bits/stdc++.h>
using namespace std;
int a, b, u;
vector<int> v1, v2;
int main() {
  cin >> a >> b;
  for (long long i = 0; i < a; ++i) {
    cin >> u;
    v1.push_back(u);
  }
  for (long long i = 0; i < b; ++i) {
    cin >> u;
    v2.push_back(u);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  for (long long i = 0; i < a; ++i) {
    for (long long j = 0; j < b; ++j) {
      if (v1[i] == v2[j]) {
        cout << v1[i];
        return 0;
      }
    }
  }
  if (v1[0] < v2[0]) {
    cout << v1[0] * 10 + v2[0];
  } else {
    cout << v2[0] * 10 + v1[0];
  }
  return 0;
}
