#include <bits/stdc++.h>
using namespace std;
const int N = 9 + 7;
int n, m;
bool A[N], B[N];
int main() {
  scanf("%d%d", &n, &m);
  int minA = 10;
  for (int i = (0); i <= (n - 1); ++i) {
    int _tmp;
    scanf("%d", &_tmp);
    minA = min(minA, _tmp);
    A[_tmp] = true;
  }
  int minB = 10;
  for (int i = (0); i <= (m - 1); ++i) {
    int _tmp;
    scanf("%d", &_tmp);
    minB = min(minB, _tmp);
    B[_tmp] = true;
  }
  for (int i = (1); i <= (9); ++i) {
    if (A[i] && B[i]) {
      printf("%d\n", i);
      return 0;
    }
  }
  if (minA > minB) {
    int _tmp = minA;
    minA = minB;
    minB = _tmp;
  }
  printf("%d%d\n", minA, minB);
  return 0;
}
