#include <bits/stdc++.h>
using namespace std;
int main() {
  int min1 = 0, max, q = 0;
  int n, m, k = 0;
  cin >> n >> m;
  if (n > m)
    max = n;
  else
    max = m;
  int a[100], b[100];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < a[0]) {
      k = a[0];
      a[0] = a[i];
      a[i] = k;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (b[i] < b[0]) {
      k = b[0];
      b[0] = b[i];
      b[i] = k;
    }
  }
  int s1 = a[0];
  int s2 = b[0];
  for (int i = 0; i < max; i++) {
    for (int k = 0; k < n; k++) {
      if (a[k] == b[i]) {
        if (q > 0 && (a[k] < min1) || q == 0) min1 = a[k];
        q++;
      }
    }
  }
  if (min1 != 0)
    cout << min1 << endl;
  else if (s1 > s2)
    cout << s2 * 10 + s1 << endl;
  else
    cout << s1 * 10 + s2 << endl;
  return 0;
}
