#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x;
  vector<int> v1;
  vector<int> v2;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v1.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    v2.push_back(x);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  for (int i = 0; i < v1.size(); i++) {
    for (int j = 0; j < v2.size(); j++) {
      if (v1[i] == v2[j]) {
        cout << v1[i] << endl;
        exit(0);
      }
    }
  }
  if (v1[0] < v2[0])
    cout << v1[0] << v2[0] << endl;
  else
    cout << v2[0] << v1[0] << endl;
}
