#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, i, k, t;
  cin >> n >> m;
  vector<int> v;
  vector<int> v1;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (i = 0; i < m; i++) {
    cin >> b;
    v1.push_back(b);
  }
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end());
  if (v[0] == v1[0])
    cout << v[0] << endl;
  else {
    int x = min(v[0], v1[0]);
    int y = max(v[0], v1[0]);
    cout << x << y << endl;
  }
}
