#include <bits/stdc++.h>
using namespace std;
double distance(int x1_coordinate, int y1_coordinate, int x2_coordinate,
                int y2_coordinate) {
  return (sqrt(pow(x2_coordinate - x1_coordinate, 2) +
               pow(y2_coordinate - y1_coordinate, 2)));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int b[m];
  for (int i = 0; i < m; i++) cin >> b[i];
  int p = *min_element(a, a + n);
  int q = *min_element(b, b + m);
  if (p == q)
    cout << p;
  else
    cout << min(p, q) << max(p, q);
  return 0;
}
