#include <bits/stdc++.h>
using namespace std;
int main() {
  int t1[22] = {0}, t2[22] = {0};
  int n, m, i, x;
  cin >> n >> m;
  while (n--) {
    cin >> x;
    t1[x] = 1;
  }
  while (m--) {
    cin >> x;
    t2[x] = 1;
  }
  for (i = 1; i <= 9; i++)
    if (t1[i] && t2[i]) {
      cout << i;
      return 0;
    }
  int m1, m2;
  for (m1 = 1; m1 <= 9; m1++)
    if (t1[m1]) break;
  for (m2 = 1; m2 <= 9; m2++)
    if (t2[m2]) break;
  if (m1 < m2)
    cout << m1 << m2;
  else
    cout << m2 << m1;
}
