#include <bits/stdc++.h>
using namespace std;
int a[100001], b[100001];
int main() {
  int n, m;
  cin >> n >> m;
  int mi1 = 100, mi2 = 100, m1 = 100;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < mi1) mi1 = a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    if (b[i] < mi2) mi2 = b[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j] && a[i] < m1) m1 = a[i];
    }
  }
  if (m1 != 100) {
    cout << m1;
    return 0;
  }
  if (mi1 < mi2)
    cout << mi1 << mi2;
  else
    cout << mi2 << mi1;
}
