#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 < m; ++i) cin >> b[i];
  sort(b, b + n);
  if (a[0] == b[0])
    cout << a[0];
  else if (a[0] < b[0])
    cout << a[0] << b[0];
  else
    cout << b[0] << a[0];
  ;
}
