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