#include <bits/stdc++.h>
using namespace std;
int n, m, a[10], b[10], m1 = 10, m2 = 10;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    m1 = min(m1, a[i]);
    m2 = min(m2, b[i]);
    int mp = 100;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i] == b[j]) mp = min(mp, a[i]);
      }
    }
    if (mp != 100) {
      cout << mp;
      return 0;
    }
    if (m1 > m2) swap(m1, m2);
    cout << m1 << m2;
  }
}
