#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(b, b + m);
  int x = a[0], y = b[0];
  if (x == y)
    cout << x;
  else {
    int k = min(x, y);
    int l = max(x, y);
    cout << k * 10 + l << endl;
  }
  return 0;
}
