#include <bits/stdc++.h>
void Solve();
int main() { Solve(); }
using namespace std;
void Solve() {
  long long n, m;
  set<long long> a;
  set<long long> b;
  cin >> n >> m;
  for (long long i = (0); i < (n); i++) {
    long long t;
    cin >> t;
    a.insert(t);
  }
  for (long long i = (0); i < (m); i++) {
    long long t;
    cin >> t;
    b.insert(t);
  }
  long long t1 = *a.begin();
  long long t2 = *b.begin();
  if (t1 == t2) {
    cout << t1;
    return;
  } else {
    cout << min(t1, t2) << max(t1, t2);
  }
}
