#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  int *p;
  cin >> n >> m;
  int n_arr[n], m_arr[m];
  for (int i = 0; i < n; i++) {
    cin >> n_arr[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> m_arr[i];
  }
  sort(n_arr, n_arr + n);
  sort(m_arr, m_arr + m);
  for (int j = 0; j < n; j++) {
    p = find(m_arr, m_arr + m, n_arr[j]);
    if (p != m_arr + m) {
      cout << *p;
      return 0;
    }
  }
  if (n_arr[0] == m_arr[0]) {
    cout << n_arr[0];
  } else if (n_arr[0] > m_arr[0]) {
    cout << m_arr[0] << n_arr[0];
  } else {
    cout << n_arr[0] << m_arr[0];
  }
}
