#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, m, a[9], b[9], mm = 10, p;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < m; i++) cin >> b[i];
  p = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
      if (a[i] == b[j] && a[i] < mm) {
        mm = a[i];
        p = 1;
      }
  if (p == 1) {
    cout << mm;
    return 0;
  }
  int amin = 10;
  for (i = 0; i < n; i++)
    if (a[i] < amin) amin = a[i];
  int bmin = 10;
  for (i = 0; i < m; i++)
    if (b[i] < bmin) bmin = b[i];
  cout << min(amin, bmin) << max(amin, bmin);
  return 0;
}
