#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long mn1 = 1e18, mn2 = mn1;
  while (n--) {
    long long x;
    cin >> x;
    mn1 = min(mn1, x);
  }
  while (m--) {
    long long x;
    cin >> x;
    mn2 = min(mn2, x);
  }
  if (mn1 == mn2) {
    return cout << mn1, 0;
  }
  return cout << min(mn1, mn2) << max(mn1, mn2), 0;
}
