#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  while (cin >> n >> m) {
    long long a, b, ma = LLONG_MAX, mi = LLONG_MAX;
    for (long long i = 0; i < n; i++) {
      cin >> a;
      ma = min(a, ma);
    }
    for (long long i = 0; i < m; i++) {
      cin >> b;
      mi = min(b, mi);
    }
    if (ma > mi) swap(ma, mi);
    if (ma == mi)
      cout << ma << endl;
    else
      cout << ma << mi << endl;
  }
  return 0;
}
